-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pill): update pill component with the new tokens (#1025)
# What <!-- Describe the technical "why" behind your changes --> ## Code Quality Checklist - [x] Lint and unit tests pass locally with my changes - [ ] I have added tests that prove my fix is effective or that my feature works (if appropriate) - [ ] I have added necessary documentation (if appropriate) - [x] I have updated storybook (if appropriate) - [ ] I have ran `yarn set-peer-dep` when adding an icon as a dependency of another component (if appropriate) [read more](https://carlsberggbs.atlassian.net/wiki/spaces/DSM/pages/4697162121/Components+as+peer+dependency) ## Jira Card <!-- if no card is associated, remove the line bellow and add "Not Applicable" --> DSM-1521
- Loading branch information
Showing
20 changed files
with
229 additions
and
168 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
Binary file modified
BIN
-904 Bytes
(87%)
cypress/snapshots/base/cypress/e2e/Pill.cy.ts/pill_base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added
BIN
+6.67 KB
cypress/snapshots/base/cypress/e2e/Pill.cy.ts/pill_textwithleadingicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.75 KB
cypress/snapshots/base/cypress/e2e/Pill.cy.ts/pill_textwithtrailingicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,53 +1,91 @@ | ||
import { IconColor, IconSize } from '@carlsberggbs/malty.atoms.base-icon'; | ||
import { globalTheme as defaultTheme } from '@carlsberggbs/malty.theme.malty-theme-provider'; | ||
import { defaultTheme } from '@carlsberggbs/malty.theme.new-malty-theme-provider'; | ||
import { useContext } from 'react'; | ||
import { ThemeContext } from 'styled-components'; | ||
import { IconTextColorProps, PillSize, PillType, UsePillStylesProps } from './Pill.types'; | ||
import { IconTextColorProps, PillSize, PillType, UsePillBackgroundColorProps, UsePillStylesProps } from './Pill.types'; | ||
|
||
export const usePillStyles = ({ size }: UsePillStylesProps) => { | ||
const theme = useContext(ThemeContext) || defaultTheme; | ||
|
||
const pillStyles = { | ||
[PillSize.ExtraSmall]: { | ||
numSize: theme.sizes.ms.value, | ||
fontSize: theme.typography.desktop.text.tiny_bold['font-size'].value, | ||
fontFamily: theme.typography.desktop.text.tiny_bold['font-family'].value, | ||
[PillSize.XS]: { | ||
numSize: theme.sizesV2.s, | ||
fontWeight: theme.typographyV2.montserrat.body[10].semibold.fontWeight, | ||
lineHeight: theme.typographyV2.montserrat.body[10].semibold.lineHeight, | ||
fontSize: theme.typographyV2.montserrat.body[10].semibold.fontSize, | ||
iconSize: IconSize.ExtraSmall, | ||
padding: theme.sizes['3xs'].value, | ||
gap: theme.sizes['4xs'].value | ||
padding: `${theme.sizesV2['4xs']} ${theme.sizesV2['3xs']}`, | ||
gap: theme.sizesV2['5xs'] | ||
}, | ||
[PillSize.Small]: { | ||
numSize: theme.sizes.m.value, | ||
fontSize: theme.typography.desktop.text.tiny_bold['font-size'].value, | ||
fontFamily: theme.typography.desktop.text.tiny_bold['font-family'].value, | ||
[PillSize.S]: { | ||
numSize: theme.sizesV2.m, | ||
fontWeight: theme.typographyV2.montserrat.body[10].semibold.fontWeight, | ||
lineHeight: theme.typographyV2.montserrat.body[10].semibold.lineHeight, | ||
fontSize: theme.typographyV2.montserrat.body[10].semibold.fontSize, | ||
iconSize: IconSize.Small, | ||
padding: theme.sizes['2xs'].value, | ||
gap: theme.sizes['3xs'].value | ||
padding: `${theme.sizesV2['4xs']} ${theme.sizesV2['3xs']}`, | ||
gap: theme.sizesV2['4xs'] | ||
}, | ||
[PillSize.Medium]: { | ||
numSize: theme.sizes.l.value, | ||
fontSize: theme.typography.desktop.text['medium-small_bold']['font-size'].value, | ||
fontFamily: theme.typography.desktop.text['medium-small_bold']['font-family'].value, | ||
[PillSize.M]: { | ||
numSize: theme.sizesV2.xl, | ||
fontWeight: theme.typographyV2.montserrat.body[14].semibold.fontWeight, | ||
lineHeight: theme.typographyV2.montserrat.body[14].semibold.lineHeight, | ||
fontSize: theme.typographyV2.montserrat.body[14].semibold.fontSize, | ||
iconSize: IconSize.Medium, | ||
padding: theme.sizes.xs.value, | ||
gap: theme.sizes['2xs'].value | ||
padding: `${theme.sizesV2['4xs']} ${theme.sizesV2['2xs']}`, | ||
gap: theme.sizesV2['4xs'] | ||
} | ||
}; | ||
|
||
return pillStyles[size]; | ||
}; | ||
|
||
export const useIconTextColor = ({ type }: IconTextColorProps) => { | ||
if ( | ||
type === PillType.Archive || | ||
type === PillType.Success || | ||
type === PillType.SuccessLight || | ||
type === PillType.AlertStrong || | ||
type === PillType.AlertLight || | ||
type === PillType.NotificationLight | ||
) { | ||
// TODO: Refactor this when the icons are reviewed with new tokens | ||
export const useIconColor = ({ type }: IconTextColorProps) => { | ||
if (type === PillType.Archive || type === PillType.Success || type === PillType.Alert) { | ||
return IconColor.DigitalBlack; | ||
} | ||
|
||
if (type === PillType.Disabled) { | ||
return IconColor.Disabled; | ||
} | ||
|
||
return IconColor.White; | ||
}; | ||
|
||
export const useTextColor = ({ type }: IconTextColorProps) => { | ||
const theme = useContext(ThemeContext) || defaultTheme; | ||
|
||
if (type === PillType.Archive || type === PillType.Success || type === PillType.Alert) { | ||
return theme.colorsV2.default.content[500]; | ||
} | ||
|
||
if (type === PillType.Disabled) { | ||
return theme.colorsV2.default.foreground.primary['interactive--disabled']; | ||
} | ||
|
||
return theme.colorsV2.default.content[100]; | ||
}; | ||
|
||
export const usePillBackgroundColor = ({ type }: UsePillBackgroundColorProps) => { | ||
const theme = useContext(ThemeContext) || defaultTheme; | ||
|
||
switch (type) { | ||
case PillType.Success: | ||
return theme.colorsV2.default.success[500]; | ||
case PillType.Alert: | ||
return theme.colorsV2.default.warning[500]; | ||
case PillType.Fail: | ||
return theme.colorsV2.default.error[600]; | ||
case PillType.Notification: | ||
return theme.colorsV2.default.information[600]; | ||
case PillType.Archive: | ||
return theme.colorsV2.default.primary[200]; | ||
case PillType.Secondary: | ||
return theme.colorsV2.default.primary[400]; | ||
case PillType.Disabled: | ||
return theme.colorsV2.default.background.primary['interactive--disabled']; | ||
default: | ||
return theme.colorsV2.default.content[500]; | ||
} | ||
}; |
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
Oops, something went wrong.