From bb28a9aed01724cebab82e781412e5cb82892f5c Mon Sep 17 00:00:00 2001 From: "hiroki.yokouchi" Date: Fri, 1 Nov 2024 15:42:04 +0900 Subject: [PATCH] feat: Unify icon size specification with other components Retain the existing specification as an alias. Signed-off-by: hiroki.yokouchi --- src/components/Icon/Icon.stories.tsx | 13 ++++++++++++ src/components/Icon/Icon.tsx | 30 +++++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/components/Icon/Icon.stories.tsx b/src/components/Icon/Icon.stories.tsx index 11faba92..2b6d657c 100644 --- a/src/components/Icon/Icon.stories.tsx +++ b/src/components/Icon/Icon.stories.tsx @@ -26,6 +26,19 @@ export const Size: Story = { + + + + + + ), + args: defaultArgs, +}; + +export const SizeAlias: Story = { + render: (args) => ( + <> + diff --git a/src/components/Icon/Icon.tsx b/src/components/Icon/Icon.tsx index c4f300fd..400b3c1b 100644 --- a/src/components/Icon/Icon.tsx +++ b/src/components/Icon/Icon.tsx @@ -7,7 +7,9 @@ import type { CSSProperties, FC } from 'react'; type Icon = keyof typeof Icons; -type IconSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl'; +type IconSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' | 'xxxl' | 'xxxxl'; +type IconSizeAlias = '2xl' | '3xl' | '4xl'; +type SizeProp = IconSize | IconSizeAlias; const toIconSizeEmValue = (size: IconSize): string => { switch (size) { @@ -21,11 +23,11 @@ const toIconSizeEmValue = (size: IconSize): string => { return '1.75rem'; case 'xl': return '2rem'; - case '2xl': + case 'xxl': return '4rem'; - case '3xl': + case 'xxxl': return '5rem'; - case '4xl': + case 'xxxxl': return '6.5rem'; default: // eslint-disable-next-line no-case-declarations @@ -34,6 +36,19 @@ const toIconSizeEmValue = (size: IconSize): string => { } }; +const normalizeSize = (icon: IconSize | IconSizeAlias): IconSize => { + switch (icon) { + case '2xl': + return 'xxl'; + case '3xl': + return 'xxxl'; + case '4xl': + return 'xxxxl'; + default: + return icon; + } +}; + type Props = { /** * アイコンの種類 @@ -45,10 +60,11 @@ type Props = { color?: TextColor; /** * サイズ - * xs=16px, sm=20px, md=24px, lg=28px, xl=32px, 2xl=64px, 3xl=80px, 4xl=104px + * xs=16px, sm=20px, md=24px, lg=28px, xl=32px, xxl=64px, xxxl=80px, xxxxl=104px + * 2xl、3xl、4xlはdeprecatedな指定となります * @default md */ - size?: IconSize; + size?: SizeProp; /** * ネイティブの`id`属性。ページで固有のIDを指定 */ @@ -65,7 +81,7 @@ type Props = { */ export const Icon: FC = ({ icon, color, size = 'md', label, ...otherProps }) => { const IconComponent = Icons[icon]; - const _sizeValue = toIconSizeEmValue(size); + const _sizeValue = toIconSizeEmValue(normalizeSize(size)); return (