Skip to content

Commit

Permalink
Merge pull request #3413 from bcgov/feat/3369
Browse files Browse the repository at this point in the history
feat(2759): add mantine color theme
  • Loading branch information
junminahn authored Jul 24, 2024
2 parents eae20a4 + c9ff432 commit 4a538cb
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 83 deletions.
140 changes: 67 additions & 73 deletions app/app/example/buttons/page.tsx
Original file line number Diff line number Diff line change
@@ -1,81 +1,75 @@
'use client';

import { MantineProvider, Button } from '@mantine/core';
import React from 'react';
import { theme } from '@/components/buttons/mantine-theme';
import { Button } from '@mantine/core';
import { IconPhoto, IconDownload, IconArrowRight } from '@tabler/icons-react';
import classNames from 'classnames';
import createClientPage from '@/core/client-page';

const ButtonsPage = () => {
const buttonConfigurations = [
{ type: 'primary', label: 'Primary' },
{ type: 'secondary', label: 'Secondary' },
{ type: 'success', label: 'Success' },
{ type: 'danger', label: 'Danger' },
{ type: 'warning', label: 'Warning' },
{ type: 'info', label: 'Info' },
];
const colors = ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark'];
const variants = ['filled', 'light', 'outline'];
const sizes = ['xl', 'compact-xl', 'lg', 'compact-lg', 'md', 'compact-md', 'sm', 'compact-sm', 'xs', 'compact-xs'];

const buttonSizes = [
{ size: 'xl', label: 'XL' },
{ size: 'lg', label: 'LG' },
{ size: 'md', label: 'MD' },
{ size: 'sm', label: 'SM' },
{ size: 'xs', label: 'XS' },
];
const buttonPage = createClientPage({
roles: ['user'],
});
export default buttonPage(() => {
return (
<div className={classNames('grid grid-cols-1 md:gap-4 md:py-2', `md:grid-cols-${colors.length}`)}>
{colors.map((color) => {
return (
<div className="col-span-1" key={color}>
{variants.map((variant) => {
return sizes.map((size) => {
return (
<div className="mb-3" key={color + variant + size}>
<div className="text-gray-800 text-sm font-bold">
{color} - {variant} - {size}
</div>
<Button color={color} variant={variant} size={size}>
{color}
</Button>
</div>
);
});
})}

const items = [];
for (let counter = 0; counter < 10; counter++) {
items.push(
<div style={{ padding: '20px', display: 'flex', flexWrap: 'wrap', gap: '50px' }}>
{buttonConfigurations.map((config) => (
<div key={config.type}>
<h2>{`${config.label} Button, #${counter + 1}:`}</h2>
<br />
{['filled', 'outline'].map((filling) =>
['button', 'disabled', 'loading'].map((variant) => (
<React.Fragment key={variant}>
<>{`${variant} ${filling}:`}</>
<br />
<Button
variant={filling}
color={`${config.type}.${counter}`}
disabled={variant.includes('disabled')}
loading={variant.includes('loading')}
>
{`${config.label} Button ${variant}`}
</Button>
<br />
<></>
<br />
</React.Fragment>
)),
)}
<div className="mb-3">
<div className="text-gray-800 text-sm font-bold">{color} - full width</div>
<Button color={color} variant={variants[0]} fullWidth>
{color}
</Button>
</div>

{['filled', 'outline'].map((filling) =>
buttonSizes.map((size) => (
<React.Fragment key={size.size}>
<Button variant={filling} color={`${config.type}.${counter}`} size={size.size}>
{`${size.label} Button`}
</Button>
<br />
<></>
<br />
</React.Fragment>
)),
)}
</div>
))}
</div>,
);
}
<div className="mb-3">
<div className="text-gray-800 text-sm font-bold">{color} - disabled</div>
<Button color={color} variant={variants[0]} disabled>
{color}
</Button>
</div>

return (
<MantineProvider theme={theme}>
<h1 style={{ fontWeight: 'bold' }}>
Suggestions of easier to maintain Mantine buttons from the task description
</h1>
{items}
</MantineProvider>
);
};
<div className="mb-3">
<div className="text-gray-800 text-sm font-bold">{color} - loading</div>
<Button color={color} variant={variants[0]} loading>
{color}
</Button>
</div>

export default ButtonsPage;
<div className="mb-3">
<div className="text-gray-800 text-sm font-bold">{color} - left icon</div>
<Button color={color} variant={variants[0]} leftSection={<IconPhoto size={14} />}>
{color}
</Button>
</div>

<div className="mb-3">
<div className="text-gray-800 text-sm font-bold">{color} - right icon</div>
<Button color={color} variant={variants[0]} rightSection={<IconDownload size={14} />}>
{color}
</Button>
</div>
</div>
);
})}
</div>
);
});
3 changes: 2 additions & 1 deletion app/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Header from '@/components/layouts/Header';
import Provider from '@/components/layouts/Provider';
import { getInfo } from '@/services/backend';
import { useAppState } from '@/states/global';
import { theme } from './mantine-theme';

const bcsans = localFont({
src: [
Expand Down Expand Up @@ -70,7 +71,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
<html lang="en">
<head></head>
<Provider>
<MantineProvider withGlobalClasses={false} withCssVariables theme={{}}>
<MantineProvider withGlobalClasses={false} withCssVariables theme={theme}>
<Notifications position="top-right" limit={5} autoClose={2500} />
<ModalsProvider>
<MainBody>{children}</MainBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ import { createTheme } from '@mantine/core';
// See https://mantine.dev/styles/variants-sizes/#adding-custom-variants
export const theme = createTheme({
colors: {
primary: generateColors('#2065a8'),

secondary: generateColors('#868E96'),

success: generateColors('#3CB371'),

primary: generateColors('#003366'),
secondary: generateColors('#868e96'),
success: generateColors('#3cb371'),
danger: generateColors('#d42222'),

warning: generateColors('#FCBA19'),

warning: generateColors('#fcba19'),
info: generateColors('#2bceff'),
dark: [
'#d5d7e0',
'#acaebf',
'#8c8fa3',
'#666980',
'#4d4f66',
'#34354a',
'#2b2c3d',
'#1d1e30',
'#0c0d21',
'#01010a',
],
},
});

0 comments on commit 4a538cb

Please sign in to comment.