-
Notifications
You must be signed in to change notification settings - Fork 54
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
Various ZUI chips 🥔 #2408
Open
ziggabyte
wants to merge
14
commits into
undocumented/new-design-system
Choose a base branch
from
undocumented/various-zui-chips
base: undocumented/new-design-system
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Various ZUI chips 🥔 #2408
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5d98bf8
Create ZUIProgressChip component + storybook story
ziggabyte 7b20039
Create ZUIDataChip component + story.
ziggabyte f805ba2
Add proper titles to the stories.
ziggabyte aa1ad6b
Create ZUITargetGroupChip + story.
ziggabyte 5f69e09
Add size property and more stories to ZUIProgressChip.
ziggabyte d34ee07
Update ZUIDataChip to have access to all data colors, improve documen…
ziggabyte eb8b91d
Update types for tags to better reflect reality.
ziggabyte b5471a4
Make placement property on ZUITooltip optional with a default for bet…
ziggabyte 9f099b8
Create ZUITagChip component + storybook story.
ziggabyte 112be3c
Create function to get the contrast color from the theme, or a calcul…
ziggabyte 07aee42
use function to get contrasting colors, set font size, make tag inlin…
ziggabyte 0e82501
Remove render function now that tags are the correct size on their ow…
ziggabyte 2dd7230
Rename folder.
ziggabyte b947d5c
Change from Object.keys to Object.values to avoid type casting.
ziggabyte 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,100 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { Box, Paper, Typography } from '@mui/material'; | ||
|
||
import ZUIDataChip from './index'; | ||
import ZUIDivider from '../ZUIDivider'; | ||
import ZUIText from '../ZUIText'; | ||
|
||
const meta: Meta<typeof ZUIDataChip> = { | ||
component: ZUIDataChip, | ||
title: 'Components/ZUIDataChip', | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof ZUIDataChip>; | ||
|
||
export const Basic: Story = { | ||
args: { | ||
color: 'grey', | ||
value: 394, | ||
}, | ||
}; | ||
|
||
export const TwoChips: Story = { | ||
args: {}, | ||
decorators: () => { | ||
return ( | ||
<Box display="flex" gap={2}> | ||
<Paper sx={{ padding: 2 }}> | ||
<Box alignItems="center" display="flex" gap={2}> | ||
<ZUIDataChip color="main" value={1240} /> | ||
<Typography variant="headingMd">Something</Typography> | ||
</Box> | ||
</Paper> | ||
<Paper sx={{ padding: 2 }}> | ||
<Box alignItems="center" display="flex" gap={2}> | ||
<ZUIDataChip color="final" value={343} /> | ||
<Typography variant="headingMd">Other thing</Typography> | ||
</Box> | ||
</Paper> | ||
</Box> | ||
); | ||
}, | ||
}; | ||
|
||
export const ThreeChips: Story = { | ||
args: {}, | ||
decorators: () => { | ||
return ( | ||
<Box display="flex" gap={2}> | ||
<Box alignItems="center" display="flex" gap={1}> | ||
<ZUIText color="secondary" variant="headingSm"> | ||
First value | ||
</ZUIText> | ||
<ZUIDivider flexItem orientation="vertical" /> | ||
<ZUIDataChip color="main" value={1240} /> | ||
</Box> | ||
<Box alignItems="center" display="flex" gap={1}> | ||
<ZUIText color="secondary" variant="headingSm"> | ||
Second value | ||
</ZUIText> | ||
<ZUIDivider flexItem orientation="vertical" /> | ||
<ZUIDataChip color="mid2" value={387} /> | ||
</Box> | ||
<Box alignItems="center" display="flex" gap={1}> | ||
<ZUIText color="secondary" variant="headingSm"> | ||
Third value | ||
</ZUIText> | ||
<ZUIDivider flexItem orientation="vertical" /> | ||
<ZUIDataChip color="final" value={343} /> | ||
</Box> | ||
</Box> | ||
); | ||
}, | ||
}; | ||
|
||
export const FourChips: Story = { | ||
args: {}, | ||
decorators: () => { | ||
return ( | ||
<Box display="flex" flexDirection="column" gap={2} width="300px"> | ||
<Box alignItems="center" display="flex" gap={1}> | ||
<ZUIDataChip color="main" value={1240} /> | ||
<ZUIText>First</ZUIText> | ||
</Box> | ||
<Box alignItems="center" display="flex" gap={1}> | ||
<ZUIDataChip color="mid3" value={231} /> | ||
<ZUIText>Second</ZUIText> | ||
</Box> | ||
<Box alignItems="center" display="flex" gap={1}> | ||
<ZUIDataChip color="mid1" value={34} /> | ||
<ZUIText>Third</ZUIText> | ||
</Box> | ||
<Box alignItems="center" display="flex" gap={1}> | ||
<ZUIDataChip color="final" value={343} /> | ||
<ZUIText>Fourth</ZUIText> | ||
</Box> | ||
</Box> | ||
); | ||
}, | ||
}; |
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,54 @@ | ||
import { Box, Typography, useTheme } from '@mui/material'; | ||
import { FC } from 'react'; | ||
|
||
type ZUIDataChipProps = { | ||
/** | ||
* Sets the color of the chip. Defaults to 'grey'. | ||
* | ||
* Note! | ||
* There are 5 purple colors available. They should be used in combos of | ||
* 2, 3 or 4 shades, like this: | ||
* | ||
* - When using 2 purple chips the correct color order is: main, final | ||
* - When using 3 purple chips the correct color order is: main, mid2, final | ||
* - When using 4 purple chips the correct color order is: main, mid3, mid1, final | ||
*/ | ||
color?: 'grey' | 'main' | 'mid1' | 'mid2' | 'mid3' | 'final'; | ||
|
||
/** | ||
* The number value to be displayed in the chip. | ||
*/ | ||
value: number; | ||
}; | ||
|
||
const ZUIDataChip: FC<ZUIDataChipProps> = ({ color = 'grey', value }) => { | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<Box | ||
bgcolor={ | ||
color == 'grey' ? theme.palette.grey[100] : theme.palette.data[color] | ||
} | ||
display="inline-flex" | ||
sx={{ | ||
borderRadius: '2rem', | ||
overflow: 'hidden', | ||
padding: '0.25rem 0.75rem', | ||
}} | ||
> | ||
<Typography | ||
sx={{ | ||
color: | ||
color == 'grey' || color == 'final' | ||
? theme.palette.common.black | ||
: theme.palette.common.white, | ||
}} | ||
variant="headingMd" | ||
> | ||
{value} | ||
</Typography> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default ZUIDataChip; |
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,50 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import ZUIProgressChip from './index'; | ||
|
||
const meta: Meta<typeof ZUIProgressChip> = { | ||
component: ZUIProgressChip, | ||
title: 'Components/ZUIProgressChip', | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof ZUIProgressChip>; | ||
|
||
export const TwoSmall: Story = { | ||
args: { | ||
values: [243, 2934], | ||
}, | ||
}; | ||
|
||
export const ThreeSmall: Story = { | ||
args: { | ||
values: [243, 2934, 3948], | ||
}, | ||
}; | ||
|
||
export const FourSmall: Story = { | ||
args: { | ||
values: [1, 2934, 34, 349], | ||
}, | ||
}; | ||
|
||
export const TwoMedium: Story = { | ||
args: { | ||
size: 'medium', | ||
values: [243, 2934], | ||
}, | ||
}; | ||
|
||
export const ThreeMedium: Story = { | ||
args: { | ||
size: 'medium', | ||
values: [243, 2934, 3948], | ||
}, | ||
}; | ||
|
||
export const FourMedium: Story = { | ||
args: { | ||
size: 'medium', | ||
values: [1, 2934, 34, 349], | ||
}, | ||
}; |
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,63 @@ | ||
import { Box, Typography, useTheme } from '@mui/material'; | ||
import { FC } from 'react'; | ||
|
||
import { ZUIMedium, ZUISmall } from '../types'; | ||
|
||
type ZUIProgressChipProps = { | ||
/** | ||
* The size of the component. Defaults to 'small'. | ||
*/ | ||
size?: ZUISmall | ZUIMedium; | ||
|
||
/** | ||
* Values to be displayed in each of the sections of the chip. | ||
* An array of 2, 3 or 4 numbers. | ||
*/ | ||
values: | ||
| [number, number] | ||
| [number, number, number] | ||
| [number, number, number, number]; | ||
}; | ||
|
||
const ZUIProgressChip: FC<ZUIProgressChipProps> = ({ | ||
size = 'small', | ||
values, | ||
}) => { | ||
const theme = useTheme(); | ||
|
||
const colors = [theme.palette.data.main, theme.palette.data.final]; | ||
|
||
//Add middle colors to the colors array | ||
if (values.length == 3) { | ||
colors.splice(1, 0, theme.palette.data.mid2); | ||
} else if (values.length == 4) { | ||
colors.splice(1, 0, theme.palette.data.mid3, theme.palette.data.mid1); | ||
} | ||
|
||
return ( | ||
<Box display="inline-flex" sx={{ borderRadius: '2em', overflow: 'hidden' }}> | ||
{values.map((value, index) => ( | ||
<Box | ||
key={`${value}-${index}`} | ||
bgcolor={colors[index]} | ||
color={ | ||
index == values.length - 1 | ||
? theme.palette.common.black | ||
: theme.palette.common.white | ||
} | ||
sx={{ | ||
borderLeft: | ||
index > 0 ? `0.063rem solid ${theme.palette.common.white}` : '', | ||
paddingLeft: index == 0 ? '0.625rem' : '0.375rem', | ||
paddingRight: index == values.length - 1 ? '0.625rem' : '0.375rem', | ||
paddingY: size == 'small' ? '0.188rem' : '0.438rem', | ||
}} | ||
> | ||
<Typography variant="labelSmMedium">{value}</Typography> | ||
</Box> | ||
))} | ||
</Box> | ||
); | ||
}; | ||
|
||
export default ZUIProgressChip; |
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,18 @@ | ||
import { getContrastColor } from 'utils/colorUtils'; | ||
import { funSwatches } from 'zui/theme/palette'; | ||
|
||
export default function getTagContrastColor(color: string) { | ||
let contrastColor = ''; | ||
|
||
Object.values(funSwatches).forEach((funSwatch) => { | ||
if (color == funSwatch.dark.color) { | ||
contrastColor = funSwatch.dark.contrast; | ||
} else if (color == funSwatch.medium.color) { | ||
contrastColor = funSwatch.medium.contrast; | ||
} else if (color == funSwatch.light.color) { | ||
contrastColor == funSwatch.light.contrast; | ||
} | ||
}); | ||
|
||
return contrastColor || getContrastColor(color); | ||
} |
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,85 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import ZUITagChip from './index'; | ||
|
||
const meta: Meta<typeof ZUITagChip> = { | ||
component: ZUITagChip, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof ZUITagChip>; | ||
|
||
export const Basic: Story = { | ||
args: { | ||
tag: { | ||
color: null, | ||
description: 'People who organize', | ||
group: null, | ||
hidden: false, | ||
id: 1, | ||
organization: { | ||
id: 1, | ||
title: 'My Organization', | ||
}, | ||
title: 'Organizer', | ||
value_type: null, | ||
}, | ||
}, | ||
}; | ||
|
||
export const ValueTag: Story = { | ||
args: { | ||
tag: { | ||
color: '#187F81', | ||
description: 'The amount this person gets paid', | ||
group: null, | ||
hidden: false, | ||
id: 1, | ||
organization: { | ||
id: 1, | ||
title: 'My Organization', | ||
}, | ||
title: 'Salary', | ||
value: '23000', | ||
value_type: 'text', | ||
}, | ||
}, | ||
}; | ||
|
||
export const BasicWithAction: Story = { | ||
args: { | ||
...Basic.args, | ||
onClick: () => null, | ||
}, | ||
render: Basic.render, | ||
}; | ||
|
||
export const ValueTagWithAction: Story = { | ||
args: { | ||
...ValueTag.args, | ||
onClick: () => null, | ||
}, | ||
}; | ||
|
||
export const DeletableBasic: Story = { | ||
args: { | ||
...Basic.args, | ||
onDelete: () => null, | ||
}, | ||
}; | ||
|
||
export const DeletableValueTag: Story = { | ||
args: { | ||
...ValueTag.args, | ||
onDelete: () => null, | ||
}, | ||
}; | ||
|
||
export const Disabled: Story = { | ||
args: { | ||
...Basic.args, | ||
disabled: true, | ||
onClick: () => null, | ||
onDelete: () => null, | ||
}, | ||
}; |
Oops, something went wrong.
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.
Very nice solution!
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.
Stolen from logic by @river-bbc :D