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 ActionIcon TASK-1448 #5412

Merged
merged 2 commits into from
Jan 20, 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
27 changes: 27 additions & 0 deletions jsapp/js/components/common/ActionIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
ActionIcon as ActionIconMantine,
} from '@mantine/core';
import type {ActionIconProps as ActionIconPropsMantine} from '@mantine/core/lib/components';
import Icon, {IconSize} from './icon';
import type {IconName} from 'jsapp/fonts/k-icons';
import {forwardRef} from 'react';

export interface ActionIconProps extends Omit<ActionIconPropsMantine, 'size'> {
iconName: IconName;
size: 'sm' | 'md' | 'lg';
}

const ActionIcon = forwardRef<HTMLButtonElement, ActionIconProps>(
({iconName, ...props}, ref) => {
// Currently, our icon sizes only use a single letter instead of
// Mantine's 'sm', 'md', etc. So here we grab the first letter.
const iconSize = props.size[0] as IconSize;
return (
<ActionIconMantine {...props} ref={ref}>
<Icon name={iconName} size={iconSize} />
</ActionIconMantine>
);
}
);

export default ActionIcon
116 changes: 116 additions & 0 deletions jsapp/js/components/common/actionIcon.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import React from 'react';
import type {Meta, StoryObj} from '@storybook/react';
import {IconNames} from 'jsapp/fonts/k-icons';
import ActionIcon, {type ActionIconProps} from './ActionIcon';

const actionIconVariants: Array<ActionIconProps['variant']> = [
'filled',
'light',

//// Custom:
'danger',
'danger-secondary',
'transparent',
];

const actionIconSizes: Array<ActionIconProps['size']> = [
'sm',
'md',
'lg',
];

export default {
title: 'common/Action Icon',
component: ActionIcon,
argTypes: {
variant: {
description: 'Variant of action icon',
options: actionIconVariants,
control: 'select',
},
size: {
description: 'Size of action icon',
options: actionIconSizes,
control: 'radio',
},
iconName: {
description: 'Icon',
options: Object.keys(IconNames),
control: {type: 'select'},
},
disabled: {control: 'boolean'},
loading: {control: 'boolean'},
},
} as Meta<typeof ActionIcon>;

type Story = StoryObj<typeof ActionIcon>;

export const Filled: Story = {
args: {
variant: 'filled',
size: 'md',
iconName: 'edit',
},
};

export const Light: Story = {
args: {
variant: 'light',
size: 'md',
iconName: 'edit',
},
};

export const Transparent: Story = {
args: {
variant: 'transparent',
size: 'md',
iconName: 'more',
},
};

export const Danger: Story = {
args: {
variant: 'danger',
size: 'md',
iconName: 'trash',
},
};

export const DangerSecondary: Story = {
args: {
variant: 'danger-secondary',
size: 'lg',
iconName: 'trash',
},
};

export const AllIconStyles = () => (
<div
style={{
display: 'grid',
gridTemplateColumns: 'repeat(3, auto)',
gridAutoFlow: 'row',
gridGap: '30px 15px',
justifyItems: 'start',
padding: '10px',
}}
>
{actionIconVariants.map((variant) =>
actionIconSizes.map((size) => {
const actionIconProps: ActionIconProps = {
variant,
size: size,
iconName: 'more',
};
return (
<>
<ActionIcon {...actionIconProps} />
<ActionIcon {...actionIconProps} loading />
<ActionIcon {...actionIconProps} disabled />
</>
);
})
)}
</div>
);
7 changes: 7 additions & 0 deletions jsapp/js/theme/kobo/ActionIcon.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.root {
jamesrkiger marked this conversation as resolved.
Show resolved Hide resolved
&[data-disabled] {
color: var(--ai-color);
background: var(--ai-bg);
opacity: 0.5;
}
}
38 changes: 38 additions & 0 deletions jsapp/js/theme/kobo/ActionIcon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {rem, ActionIcon} from '@mantine/core';
import classes from './ActionIcon.module.css';

export const ActionIconThemeKobo = ActionIcon.extend({
classNames: classes,
vars: (theme, props) => {
return {
root: {
'--ai-size-sm': rem(28),
'--ai-size-md': rem(32),
'--ai-size-lg': rem(38),

...(props.variant === 'filled' && {
'--ai-hover': theme.colors.blue[5],
}),
...(props.variant === 'light' && {
'--ai-color': theme.colors.blue[4],
'--ai-bg': theme.colors.blue[9],
'--ai-hover': theme.colors.blue[8],
}),
...(props.variant === 'transparent' && {
'--ai-color': theme.colors.blue[4],
'--ai-hover-color': theme.colors.blue[5],
}),
...(props.variant === 'danger' && {
'--ai-color': 'var(--mantine-color-white)',
'--ai-bg': theme.colors.red[6],
'--ai-hover': theme.colors.red[5],
}),
...(props.variant === 'danger-secondary' && {
'--ai-color': theme.colors.red[5],
'--ai-bg': theme.colors.red[9],
'--ai-hover': theme.colors.red[8],
}),
},
};
},
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Menu} from '@mantine/core';
import classes from './menu.module.css';
import classes from './Menu.module.css';

declare module '@mantine/core' {
export interface MenuItemProps {
Expand Down
4 changes: 3 additions & 1 deletion jsapp/js/theme/kobo/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {createTheme, rem} from '@mantine/core';
import {ActionIconThemeKobo} from './ActionIcon';
import {ButtonThemeKobo} from './Button';
import {TableThemeKobo} from './Table';
import {TooltipThemeKobo} from './Tooltip';
import {MenuThemeKobo} from './menu';
import {MenuThemeKobo} from './Menu';

export const themeKobo = createTheme({
primaryColor: 'blue',
Expand Down Expand Up @@ -87,6 +88,7 @@ export const themeKobo = createTheme({
},

components: {
ActionIcon: ActionIconThemeKobo,
Button: ButtonThemeKobo,
Menu: MenuThemeKobo,
Tooltip: TooltipThemeKobo,
Expand Down
Loading