Skip to content

Commit

Permalink
feat(organizations): add theming/story for Mantine Modal TASK-1423 (#…
Browse files Browse the repository at this point in the history
…5432)

### 📣 Summary
Theming for Mantine's Modal was added to match Kobo's current KoboModal
used for general purpose.



### 📖 Description
* Co-authored by @duvld 

- We don't have a direct reference of an existing Kobo component, so
we've came up a middle ground between the existing modals using though
the application.
- We have added a Story with a big set of configurations to showcase the
possibilities of the Modal
- The story also displays a way of 
- We added a theme and style to the Modal component
- Title is using the default heading weight



### 👀 Preview steps
- Use storybook to check the visual of the component.
  • Loading branch information
pauloamorimbr authored Jan 27, 2025
1 parent 2091624 commit 45e01f4
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 1 deletion.
82 changes: 82 additions & 0 deletions jsapp/js/components/common/modal.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import type {ModalProps} from '@mantine/core';
import {Button, Center, Modal, Stack, Text, Group} from '@mantine/core';
import type {Meta, StoryObj} from '@storybook/react';
import {useArgs} from '@storybook/preview-api';

const RenderModal = ({...args}: ModalProps) => {
const [{opened}, updateArgs] = useArgs();

return (
<Center w={400} h={80}>
<Button onClick={() => updateArgs({opened: !opened})}>Open modal</Button>
<Modal {...args} onClose={() => updateArgs({opened: !opened})}>
<Stack>
<Text p='md'>
Example modal content. Press esc, click outside or close button to
close.
</Text>
<Group justify='flex-end'>
<Button variant='danger'>Won&apos;t close</Button>
<Button onClick={() => updateArgs({opened: false})}>Close</Button>
</Group>
</Stack>
</Modal>
</Center>
);
};

/**
* Mantine [Modal](https://mantine.dev/core/modal/) component stories.
*/
const meta: Meta<typeof Modal> = {
title: 'Common/Modal',
component: Modal,
render: RenderModal,
argTypes: {
opened: {
description: 'Modal opened state',
type: 'boolean',
},
size: {
description: 'Modal size - influences the width of the modal, height depends on the content',
type: 'string',
control: {
type: 'select',
},
options: ['auto', 'xs', 'sm', 'md', 'lg', 'xl', '50%', '75%', '100%'],
},
fullScreen: {
description: 'Modal fullscreen state',
type: 'boolean',
},
centered: {
description: 'Center modal vertically on the viewport',
type: 'boolean',
},
withCloseButton: {
description: 'Render close button',
type: 'boolean',
},
title: {
description: 'Modal title',
type: 'string',
},
},
args: {
opened: false,
closeOnClickOutside: true,
withCloseButton: true,
title: 'Modal title',
centered: false,
size: 'md',
fullScreen: false,
},
};

type Story = StoryObj<typeof Modal>;

export const Basic: Story = {
args: {},
};

export default meta;
2 changes: 1 addition & 1 deletion jsapp/js/components/modals/koboModal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Button from '../common/button';
import KoboPrompt from './koboPrompt';

export default {
title: 'common/KoboModal',
title: 'commonDeprecated/KoboModal',
component: KoboModal,
argTypes: {
isOpen: {control: 'boolean'},
Expand Down
15 changes: 15 additions & 0 deletions jsapp/js/theme/kobo/Modal.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.close {
color: var(--mantine-color-gray-4);
background-color: transparent;

&:hover {
color: var(--mantine-color-gray-2);
background-color: transparent;
}
}

.title {
font-size: var(--mantine-font-size-xl);
font-weight: var(--mantine-heading-font-weight);
color: var(--mantine-color-gray-0);
}
18 changes: 18 additions & 0 deletions jsapp/js/theme/kobo/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {Modal} from '@mantine/core';
import Icon from 'jsapp/js/components/common/icon';
import classes from './Modal.module.css';

export const ModalThemeKobo = Modal.extend({
defaultProps: {
closeButtonProps: {
icon: <Icon name='close' />,
},
overlayProps: {
backgroundOpacity: 0.5,
color: 'var(--mantine-color-blue-9)',
zIndex: 3000,
},
zIndex: 4000,
},
classNames: classes,
});
2 changes: 2 additions & 0 deletions jsapp/js/theme/kobo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {MenuThemeKobo} from './Menu';
import {AlertThemeKobo} from './Alert';
import {SelectThemeKobo} from './Select';
import {LoaderThemeKobo} from './Loader';
import {ModalThemeKobo} from './Modal';

export const themeKobo = createTheme({
primaryColor: 'blue',
Expand Down Expand Up @@ -110,5 +111,6 @@ export const themeKobo = createTheme({
Table: TableThemeKobo,
Select: SelectThemeKobo,
Loader: LoaderThemeKobo,
Modal: ModalThemeKobo,
},
});

0 comments on commit 45e01f4

Please sign in to comment.