Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(organizations): add theming/story for Mantine Loader and LoadingOverlay TASK-1464 #5425

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions jsapp/js/components/common/loader.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {Center, Loader} from '@mantine/core';
import type {Meta, StoryObj} from '@storybook/react';

/**
* Mantine [Loader](https://mantine.dev/core/loader/) component stories.
*/
const meta: Meta<typeof Loader> = {
title: 'Common/Loader',
component: Loader,
decorators: [
(Story) => (
<Center w='400' p='md'>
<Story />
</Center>
),
],
argTypes: {
type: {
description: 'Select loader type',
options: ['regular', 'big'],
control: 'radio',
},
},
};

type Story = StoryObj<typeof Loader>;

/**
* Regular variant
*/
export const Regular: Story = {
args: {
type: 'regular',
},
};

/**
* Big variant
*/
export const Big: Story = {
args: {
type: 'big',
},
};

export default meta;
77 changes: 77 additions & 0 deletions jsapp/js/components/common/loadingOverlay.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {
Button,
Card,
Center,
LoadingOverlay,
PasswordInput,
Stack,
Text,
TextInput,
} from '@mantine/core';
import type {Meta, StoryObj} from '@storybook/react';

/**
* Mantine [LoadingOverlay](https://mantine.dev/core/loading-overlay/) component stories.
*
* Component used to display an overlay over the sibling content containing the Loader component
*/
const meta: Meta<typeof LoadingOverlay> = {
title: 'Common/LoadingOverlay',
component: LoadingOverlay,
decorators: [
(Story) => (
<Center w='400' p='md'>
<Stack gap='md'>
<Card w='300' p='md' withBorder>
<Stack gap='md'>
<Story />
<Text>Sibling components...</Text>
<TextInput label='User' placeholder='Type something...' />
<PasswordInput label='Password' placeholder='Type something...' />
<Button>Submit</Button>
</Stack>
</Card>
<Button>Button not sibling</Button>
</Stack>
</Center>
),
],
argTypes: {
visible: {
description: 'Controls overlay visibility',
control: 'boolean',
},
},
};

type Story = StoryObj<typeof LoadingOverlay>;

/**
* LoadingOverlay component visible
*/
export const Visible: Story = {
args: {
visible: true,
},
};

/**
* LoadingOverlay component not visible
*/
export const NotVisible: Story = {
args: {
visible: false,
},
};

/**
* Using 'big' variant
*/
export const Big: Story = {
args: {
visible: true,
loaderProps: {type: 'big'},
},
};

export default meta;
29 changes: 29 additions & 0 deletions jsapp/js/theme/kobo/Loader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type {MantineLoaderComponent} from '@mantine/core';
import {Box, Loader} from '@mantine/core';
import LoadingSpinner from 'jsapp/js/components/common/loadingSpinner';
import {forwardRef} from 'react';

const KoboLoaderRegular: MantineLoaderComponent = forwardRef(
({...others}, ref) => (
<Box component='span' {...others} ref={ref}>
<LoadingSpinner message={false} />
</Box>
)
);

const KoboLoaderBig: MantineLoaderComponent = forwardRef(({...others}, ref) => (
<Box component='span' {...others} ref={ref}>
<LoadingSpinner message={false} type='big' />
</Box>
));

export const LoaderThemeKobo = Loader.extend({
defaultProps: {
loaders: {
...Loader.defaultLoaders,
regular: KoboLoaderRegular,
big: KoboLoaderBig,
},
type: 'regular',
},
});
5 changes: 3 additions & 2 deletions jsapp/js/theme/kobo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {TooltipThemeKobo} from './Tooltip';
import {MenuThemeKobo} from './Menu';
import {AlertThemeKobo} from './Alert';
import {SelectThemeKobo} from './Select';
import {LoaderThemeKobo} from './Loader';

export const themeKobo = createTheme({
primaryColor: 'blue',
Expand Down Expand Up @@ -83,8 +84,7 @@ export const themeKobo = createTheme({
lg: rem(16),
xl: rem(18),
},
lineHeights: {
},
lineHeights: {},
headings: {
fontWeight: '500',
},
Expand All @@ -109,5 +109,6 @@ export const themeKobo = createTheme({
Tooltip: TooltipThemeKobo,
Table: TableThemeKobo,
Select: SelectThemeKobo,
Loader: LoaderThemeKobo,
},
});
Loading