-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui kit icons): create icon-utils file and export getIconStyles, T…
…IconProps, and TSVGProps from design system package to enable importing these methods/types in a defined namespace in svgr template, remove unnecessary index.tsx files from all generated icon folders (#3009)
- Loading branch information
1 parent
912fbbc
commit 7b1a6ce
Showing
8 changed files
with
145 additions
and
143 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,8 @@ | ||
--- | ||
'@commercetools-uikit/rich-text-utils': minor | ||
'@commercetools-uikit/checkbox-input': minor | ||
'@commercetools-uikit/icons': minor | ||
'@commercetools-uikit/design-system': minor | ||
--- | ||
|
||
Add icon-utils to design-system package so that icon styling boilerplate can be standardized and reduced, remove extraneous index.tsx in favor of index.ts files in each generated icon file" |
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,118 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { css } from '@emotion/react'; | ||
import designTokens from './design-tokens'; | ||
|
||
export type TIconProps = { | ||
color?: | ||
| 'solid' | ||
| 'neutral60' | ||
| 'surface' | ||
| 'info' | ||
| 'primary' | ||
| 'primary40' | ||
| 'warning' | ||
| 'error' | ||
| 'success'; | ||
/** | ||
* The size of the icon. 'small', 'medium', 'big' have been deprecated in favor of '10', '20', '30', '40'. | ||
*/ | ||
size?: 'small' | 'medium' | 'big' | 'scale' | '10' | '20' | '30' | '40'; | ||
}; | ||
export type TSVGProps = TIconProps & { className: string }; | ||
|
||
const iconSizes = { | ||
small: 12, | ||
medium: 16, | ||
big: 24, | ||
'10': 12, | ||
'20': 16, | ||
'30': 20, | ||
'40': 24, | ||
} as const; | ||
const getSizeDimensions = (size: TIconProps['size']) => { | ||
switch (size) { | ||
case 'scale': | ||
return { width: '100%', height: 'auto' }; | ||
case 'small': | ||
case 'medium': | ||
case 'big': | ||
case '10': | ||
case '20': | ||
case '30': | ||
case '40': | ||
return { width: `${iconSizes[size]}px`, height: `${iconSizes[size]}px` }; | ||
default: | ||
return { width: `${iconSizes['40']}px`, height: `${iconSizes['40']}px` }; | ||
} | ||
}; | ||
const getSizeStyle = (size: TIconProps['size']) => { | ||
const dimensions = getSizeDimensions(size); | ||
switch (size) { | ||
case 'scale': | ||
return ` | ||
&:not(:root) { | ||
width: ${dimensions.width}; | ||
height: ${dimensions.height}; | ||
} | ||
`; | ||
default: | ||
return ` | ||
width: ${dimensions.width}; | ||
height: ${dimensions.height}; | ||
`; | ||
} | ||
}; | ||
|
||
const getColor = (color: TIconProps['color']) => { | ||
if (!color) return 'inherit'; | ||
|
||
let iconColor; | ||
switch (color) { | ||
case 'solid': | ||
iconColor = designTokens.colorSolid; | ||
break; | ||
case 'neutral60': | ||
iconColor = designTokens.colorNeutral60; | ||
break; | ||
case 'surface': | ||
iconColor = designTokens.colorSurface; | ||
break; | ||
case 'info': | ||
iconColor = designTokens.colorInfo; | ||
break; | ||
case 'primary': | ||
iconColor = designTokens.colorPrimary; | ||
break; | ||
case 'primary40': | ||
iconColor = designTokens.colorPrimary40; | ||
break; | ||
case 'warning': | ||
iconColor = designTokens.colorWarning; | ||
break; | ||
case 'error': | ||
iconColor = designTokens.colorError; | ||
break; | ||
case 'success': | ||
iconColor = designTokens.colorSuccess; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
if (!iconColor) { | ||
return 'inherit'; | ||
} | ||
|
||
return iconColor; | ||
}; | ||
|
||
export const getIconStyles = (props: TIconProps) => css` | ||
*:not([fill='none']) { | ||
fill: ${getColor(props.color)}; | ||
} | ||
&, | ||
image { | ||
${getSizeStyle(props.size)}; | ||
} | ||
flex-shrink: 0; | ||
`; |
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 +1,17 @@ | ||
export type { Props, SVGProps } from './templates/icon.styles'; | ||
export type Props = { | ||
color?: | ||
| 'solid' | ||
| 'neutral60' | ||
| 'surface' | ||
| 'info' | ||
| 'primary' | ||
| 'primary40' | ||
| 'warning' | ||
| 'error' | ||
| 'success'; | ||
/** | ||
* The size of the icon. 'small', 'medium', 'big' have been deprecated in favor of '10', '20', '30', '40'. | ||
*/ | ||
size?: 'small' | 'medium' | 'big' | 'scale' | '10' | '20' | '30' | '40'; | ||
}; | ||
export type SVGProps = Props & { className: string }; |
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
packages/components/inputs/checkbox-input/src/icons/generated/index.tsx
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
packages/components/inputs/rich-text-utils/src/rich-text-body/icons/generated/index.tsx
This file was deleted.
Oops, something went wrong.