-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(label): add experimental label component (#471)
* feat(label): add Label * feat(essentials): add darkTheme css util * feat(essentials): add bare color value getters * docs(label): add examples * fix(label): add nowrap --------- Co-authored-by: Lena Rashkovan <lena.rashkovan@free-now.com>
- Loading branch information
Showing
5 changed files
with
139 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import styled from 'styled-components'; | ||
import { variant } from 'styled-system'; | ||
import React, { ComponentPropsWithoutRef, ReactElement } from 'react'; | ||
import { textStyles } from '../Text/Text'; | ||
import { getSemanticValue } from '../../../essentials/experimental/cssVariables'; | ||
import { get } from '../../../utils/experimental/themeGet'; | ||
|
||
type LabelType = 'default' | 'positive' | 'negative'; | ||
|
||
interface LabelProps extends ComponentPropsWithoutRef<'span'> { | ||
/** | ||
* Set the appropriate colors for the component with 'default' as a default | ||
*/ | ||
type?: LabelType; | ||
} | ||
|
||
const variantStyles = variant({ | ||
prop: '$type', | ||
variants: { | ||
default: { | ||
color: getSemanticValue('on-surface'), | ||
backgroundColor: getSemanticValue('surface-variant') | ||
}, | ||
positive: { | ||
color: getSemanticValue('on-positive-container'), | ||
backgroundColor: getSemanticValue('positive-container') | ||
}, | ||
negative: { | ||
color: getSemanticValue('on-negative-container'), | ||
backgroundColor: getSemanticValue('negative-container') | ||
} | ||
} | ||
}); | ||
|
||
const StyledLabel = styled.span<{ $type: LabelType }>` | ||
display: inline-flex; | ||
box-sizing: border-box; | ||
border-radius: ${get('radii.2')}; | ||
padding: ${get('space.1')} ${get('space.2')}; | ||
white-space: nowrap; | ||
${textStyles.variants.label2}; | ||
${props => variantStyles(props)} | ||
`; | ||
|
||
function Label({ children, type = 'default', ...restProps }: LabelProps): ReactElement { | ||
return ( | ||
<StyledLabel $type={type} {...restProps}> | ||
{children} | ||
</StyledLabel> | ||
); | ||
} | ||
|
||
export { Label, LabelProps }; |
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,56 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { StoryObj, Meta } from '@storybook/react'; | ||
import { Label } from '../Label'; | ||
import { darkTheme, getBareValue } from '../../../../essentials/experimental'; | ||
|
||
const meta: Meta = { | ||
title: 'Experimental/Components/Label', | ||
component: Label, | ||
parameters: { | ||
layout: 'centered' | ||
}, | ||
args: { | ||
children: 'Label Text' | ||
}, | ||
argTypes: { | ||
type: { | ||
control: 'radio', | ||
options: ['default', 'positive', 'negative'] | ||
} | ||
} | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Label>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const Positive: Story = { | ||
args: { | ||
type: 'positive' | ||
} | ||
}; | ||
|
||
export const Negative: Story = { | ||
args: { | ||
type: 'negative' | ||
} | ||
}; | ||
|
||
export const Custom: Story = { | ||
render: ({ children, ...props }) => { | ||
const CustomLabel = styled(Label)` | ||
color: ${getBareValue('neutral-99')}; | ||
background-color: ${getBareValue('blue-50')}; | ||
${darkTheme` | ||
color: ${getBareValue('neutral-10')}; | ||
background-color: ${getBareValue('blue-70')}; | ||
`} | ||
`; | ||
|
||
return <CustomLabel {...props}>{children}</CustomLabel>; | ||
} | ||
}; |
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
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './theme'; | ||
export { createGlobalStyle, ColorPalette } from './Colors'; | ||
export { darkTheme } from './globalStyles'; | ||
export { getSemanticValue, getBareValue, getBareHslValue, getSemanticHslValue } from './cssVariables'; |