-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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(novui): Map panda values to mantine theme #5692
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react'; | ||
import { StoryFn, Meta } from '@storybook/react'; | ||
import { Button } from './Button'; | ||
import { Flex } from '../../../styled-system/jsx'; | ||
import { Icon10K, IconInfo } from '../../icons'; | ||
|
||
export default { | ||
title: 'Components/Button', | ||
component: Button, | ||
argTypes: {}, | ||
} as Meta<typeof Button>; | ||
|
||
const Template: StoryFn<typeof Button> = ({ ...args }) => <Button {...args}>Click Me</Button>; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = {}; | ||
|
||
export const Loading = Template.bind({}); | ||
Loading.args = { | ||
loading: true, | ||
}; | ||
|
||
export const icon = () => ( | ||
<Flex> | ||
<Button size="lg" Icon={Icon10K}> | ||
Large | ||
</Button> | ||
<Button Icon={IconInfo}>Medium</Button> | ||
</Flex> | ||
); | ||
|
||
export const filled = () => ( | ||
<Flex> | ||
<Button size="lg">Large</Button> | ||
<Button>Medium</Button> | ||
</Flex> | ||
); | ||
|
||
export const outline = () => ( | ||
<Flex> | ||
<Button size="lg" variant="outline"> | ||
Large | ||
</Button> | ||
<Button variant="outline">Medium</Button> | ||
</Flex> | ||
); | ||
|
||
export const disabled = () => ( | ||
<Flex> | ||
<Button disabled>Filled</Button> | ||
<Button variant="outline" disabled> | ||
Outline | ||
</Button> | ||
</Flex> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { FC } from 'react'; | ||
import { CorePropsWithChildren } from '../../types'; | ||
import { Button as ExternalButton, ButtonProps } from '@mantine/core'; | ||
import { IconType } from '../../icons'; | ||
import { css } from '../../../styled-system/css'; | ||
|
||
export interface IButtonProps | ||
extends CorePropsWithChildren, | ||
React.ButtonHTMLAttributes<HTMLButtonElement>, | ||
Pick<ButtonProps, 'size' | 'variant'> { | ||
Icon?: IconType; | ||
} | ||
|
||
export const Button: FC<IButtonProps> = ({ children, Icon, size = 'md', variant = 'filled', ...buttonProps }) => { | ||
return ( | ||
<ExternalButton | ||
size={size} | ||
leftSection={Icon ? <Icon title="button-icon" size="16" className={css({ color: 'legacy.white' })} /> : undefined} | ||
variant={variant} | ||
{...buttonProps} | ||
> | ||
{children} | ||
</ExternalButton> | ||
); | ||
}; | ||
antonjoel82 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Button'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { MantineColorsTuple, MantineThemeOverride } from '@mantine/core'; | ||
import { COLOR_PALETTE_TOKENS } from '../tokens/colors.tokens'; | ||
import { token, Token } from '../../styled-system/tokens'; | ||
|
||
/** | ||
* Generates a Mantine color tuple for the given Panda color "family" | ||
*/ | ||
const generateMantineColorTokens = (colorFamily: keyof typeof COLOR_PALETTE_TOKENS): MantineColorsTuple => { | ||
return Object.keys(COLOR_PALETTE_TOKENS[colorFamily]).map((paletteNumber) => | ||
token(`colors.${colorFamily}.${paletteNumber}.dark` as Token) | ||
) as unknown as MantineColorsTuple; | ||
}; | ||
|
||
/** Maps Panda token values to a mantine theme config */ | ||
export const MANTINE_THEME: MantineThemeOverride = { | ||
// colors | ||
white: token('colors.legacy.white'), | ||
black: token('colors.legacy.black'), | ||
primaryColor: 'gradient', | ||
primaryShade: 6, | ||
colors: { | ||
gray: generateMantineColorTokens('mauve'), | ||
yellow: generateMantineColorTokens('amber'), | ||
blue: generateMantineColorTokens('blue'), | ||
green: generateMantineColorTokens('green'), | ||
red: generateMantineColorTokens('red'), | ||
// must have a tuple of 10 strings, but replace the value at primaryShade with our gradient | ||
antonjoel82 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
gradient: ['', '', '', '', '', '', token('gradients.horizontal'), '', '', ''], | ||
}, | ||
|
||
// typography | ||
fontFamily: token('fonts.system'), | ||
fontFamilyMonospace: token('fonts.mono'), | ||
lineHeights: { | ||
sm: token('lineHeights.100'), | ||
md: token('lineHeights.125'), | ||
lg: token('lineHeights.150'), | ||
// missing 175 | ||
xl: token('lineHeights.200'), | ||
}, | ||
headings: { | ||
fontFamily: token('fonts.system'), | ||
fontWeight: token('fontWeights.strong'), | ||
sizes: { | ||
// page title | ||
h1: { | ||
fontSize: token('fontSizes.150'), | ||
lineHeight: token('lineHeights.200'), | ||
}, | ||
// section title | ||
h2: { | ||
fontSize: token('fontSizes.125'), | ||
lineHeight: token('lineHeights.175'), | ||
}, | ||
// subsection title | ||
h3: { | ||
fontSize: token('fontSizes.100'), | ||
lineHeight: token('lineHeights.150'), | ||
}, | ||
}, | ||
}, | ||
|
||
// TODO: these are guesses for how they match up | ||
spacing: { | ||
xs: token('spacing.25'), | ||
sm: token('spacing.50'), | ||
md: token('spacing.100'), | ||
lg: token('spacing.150'), | ||
xl: token('spacing.200'), | ||
xxl: token('spacing.250'), | ||
xxxl: token('spacing.300'), | ||
}, | ||
radius: { | ||
xs: token('radii.xs'), | ||
sm: token('radii.s'), | ||
md: token('radii.m'), | ||
lg: token('radii.l'), | ||
}, | ||
defaultRadius: 'md', | ||
shadows: { | ||
// TODO: this makes no sense except for md | ||
sm: token('shadows.light'), | ||
md: token('shadows.medium'), | ||
lg: token('shadows.dark'), | ||
xl: token('shadows.color'), | ||
}, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 thought (non-blocking): Is there a semantic token we can use to replace
legacy.white
for the color here? Not a major, but would be good to reach a point where we can stop using legacy stuff.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, that is just a placeholder for testing. We're going to need quite a bit more customization for our buttons.
I'm going to have to meet with Nik when he's back though because the colors are in a confusing state right now, and it's difficult to discern from designs what maps to what.