Skip to content
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

Convert enum type of component props to string literal type - Toast, Tooltip, etc #1990

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c7530b9
feat(codemod): comment import declaration check for internal use
yangwooseong Feb 7, 2024
6b84364
feat(modal): convert `ModalTitleSize` enum to string literal
yangwooseong Feb 8, 2024
8d91d9d
feat(toast): convert `ToastPlacement`, `ToastAppearnce`, `ToastPreset…
yangwooseong Feb 8, 2024
ed90814
feat(spinner): convert `SpinnerSize` enum to string literal
yangwooseong Feb 8, 2024
704896d
feat(spinner): rm deprecated `SpinnerThickness` prop
yangwooseong Feb 8, 2024
21e25e4
feat(switch): rm deprecated `SwitchSize` prop
yangwooseong Feb 8, 2024
ab173a9
feat(tooltip): convert `TooltipPosition` enum to string literal
yangwooseong Feb 8, 2024
f417e15
feat(overlay): conver `OverlayPosition` enum to string literal
yangwooseong Feb 8, 2024
2135073
feat(progress-bar): deprecate `ProgressBarSize`, `ProgressBarVariant`…
yangwooseong Feb 9, 2024
4217ad3
feat(legacy-tooltip): convert `LegacyTooltipPosition` enum to string …
yangwooseong Feb 9, 2024
43a716c
feat(text-field): convert `TextFieldSize`, `TextFieldVariant` enum t…
yangwooseong Feb 9, 2024
9e7dbf7
feat(tag-badge): convert `TagBadgeSize`, `TagBadgeVariant` enum to s…
yangwooseong Feb 9, 2024
06edcf6
feat(icon): convert `IconSize` enum to string literal
yangwooseong Feb 13, 2024
aa75892
feat(text-area): convert `TextAreaHeight` enum to number literal
yangwooseong Feb 13, 2024
4cc7cc7
feat(avatar-group): convert `AvatarGroupEllipsisType` enum to string …
yangwooseong Feb 13, 2024
cac5dd9
Revert "feat(codemod): comment import declaration check for internal …
yangwooseong Feb 13, 2024
622891d
feat(codemod): resolve typecheck error
yangwooseong Feb 13, 2024
b6b310f
feat(storybook): rm unused util
yangwooseong Feb 13, 2024
81f7b7d
chore(changeset): add
yangwooseong Feb 13, 2024
cfff23b
chore(storybook): resolve runtime error caused by using dead code
yangwooseong Feb 13, 2024
814b551
chore: check in jsdoc
yangwooseong Feb 13, 2024
8530787
chore(badge): update snapshot
yangwooseong Feb 13, 2024
8dd616d
feat(storybook): rm utils/story path from tsconfig
yangwooseong Feb 13, 2024
297b174
feat(icon): change normal to m
yangwooseong Feb 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .changeset/gold-gorillas-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
"@channel.io/bezier-react": major
---

**Breaking Changes: The enum type that the component receives as props is changed to a string (or number) literal type**

The properties that change are:

- `AvatarGroupEllipsisType`
- `IconSize`
- `LegacyTooltipPosition`
- `ModalTitleSize`
- `OverlayPosition`
- `ProgressBarSize`, `ProgressBarVariant`
- `SpinnerSize`
- `SwitchSize`
- `TagBadgeSize`, `TagBadgeVariant`
- `TextAreaHeight`
- `TextFieldSize`, `TextFieldVariant`
- `ToastPlacement`, `ToastAppearance`, `ToastPreset`
- `TooltipPosition`

Also, `SpinnerThickness` props of `Spinner` is not supported any more.

When changed to string literal type, it is changed to the kebab-cased value of enum. e.g. `TooltipPosition.TopCenter` -> `top-center`. Among the above enums, `TextAreaHeight` is converted to number literal type. e.g. `TextAreaHeight.Row16` -> `16`, and `IconSize.normal` is converted to `m` for consistency
19 changes: 19 additions & 0 deletions .changeset/smart-ravens-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
"@channel.io/bezier-codemod": minor
---

Add more various cases to `v2-enum-member-to-string-literal`. Now it covers following enums.

- `AvatarGroupEllipsisType`
- `IconSize`
- `LegacyTooltipPosition`
- `ModalTitleSize`
- `OverlayPosition`
- `ProgressBarSize`, `ProgressBarVariant`
- `SpinnerSize`
- `SwitchSize`
- `TagBadgeSize`, `TagBadgeVariant`
- `TextAreaHeight`
- `TextFieldSize`, `TextFieldVariant`
- `ToastPlacement`, `ToastAppearance`, `ToastPreset`
- `TooltipPosition`
2 changes: 1 addition & 1 deletion packages/bezier-codemod/src/shared/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {

type Name = string
type Member = string
type Value = string
type Value = string | number
export type EnumTransformMap = Record<Name, Record<Member, Value>>

export const transformEnumToStringLiteralInBezier = (sourceFile: SourceFile, enumTransforms: EnumTransformMap) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,141 @@ const ENUM_TRANSFORM_MAP: EnumTransformMap = {
GreenAlt: 'green-alt',
Monochrome: 'monochrome',
},
ModalTitleSize: {
L: 'l',
M: 'm',
},
ToastPlacement: {
BottomLeft: 'bottom-left',
BottomRight: 'bottom-right',
},
ToastAppearance: {
Success: 'success',
Warning: 'warning',
Error: 'error',
Info: 'info',
},
ToastPreset: {
Default: 'default',
Success: 'success',
Error: 'error',
Offline: 'offline',
Online: 'online',
},
SpinnerSize: {
XL: 'xl',
L: 'l',
M: 'm',
S: 's',
XS: 'xs',
},
SwitchSize: {
M: 'm',
S: 's',
},
TooltipPosition: {
TopCenter: 'top-center',
TopLeft: 'top-left',
TopRight: 'top-right',
RightCenter: 'right-center',
RightTop: 'right-top',
RightBottom: 'right-bottom',
BottomCenter: 'bottom-center',
BottomLeft: 'bottom-left',
BottomRight: 'bottom-right',
LeftCenter: 'left-center',
LeftTop: 'left-top',
LeftBottom: 'left-bottom',
},
LegacyTooltipPosition: {
TopCenter: 'top-center',
TopLeft: 'top-left',
TopRight: 'top-right',
RightCenter: 'right-center',
RightTop: 'right-top',
RightBottom: 'right-bottom',
BottomCenter: 'bottom-center',
BottomLeft: 'bottom-left',
BottomRight: 'bottom-right',
LeftCenter: 'left-center',
LeftTop: 'left-top',
LeftBottom: 'left-bottom',
},
OverlayPosition: {
TopCenter: 'top-center',
TopLeft: 'top-left',
TopRight: 'top-right',
RightCenter: 'right-center',
RightTop: 'right-top',
RightBottom: 'right-bottom',
BottomCenter: 'bottom-center',
BottomLeft: 'bottom-left',
BottomRight: 'bottom-right',
LeftCenter: 'left-center',
LeftTop: 'left-top',
LeftBottom: 'left-bottom',
InnerLeftTop: 'inner-left-top',
InnerLeftBottom: 'inner-left-bottom',
InnerRightTop: 'inner-right-top',
InnerRightBottom: 'inner-right-bottom',
},
TextFieldType: {
Search: 'search',
Text: 'text',
Email: 'email',
Password: 'password',
Tel: 'tel',
Url: 'url',
Hidden: 'hidden',
Number: 'number',
},
TextFieldVariant: {
Primary: 'primary',
Secondary: 'secondary',
},
TagBadgeVariant: {
Default: 'default',
MonochromeLight: 'monochrome-light',
MonochromeDark: 'monochrome-dark',
Blue: 'blue',
Cobalt: 'cobalt',
Teal: 'teal',
Green: 'green',
Olive: 'olive',
Pink: 'pink',
Navy: 'navy',
Yellow: 'yellow',
Orange: 'orange',
Red: 'red',
Purple: 'purple',
},
TagBadgeSize: {
XS: 'xs',
S: 's',
M: 'm',
L: 'l',
},
IconSize: {
XL: 'xl',
L: 'l',
Normal: 'm',
S: 's',
XS: 'xs',
XXS: 'xxs',
XXXS: 'xxxs',
},
TextAreaHeight: {
Row3: 3,
Row6: 6,
Row10: 10,
Row16: 16,
Row24: 24,
Row36: 36,
},
AvatarGroupEllipsisType: {
Icon: 'icon',
Count: 'count',
},
}

function enumMemberToStringLiteral(sourceFile: SourceFile): true | void {
Expand Down
2 changes: 1 addition & 1 deletion packages/bezier-codemod/src/utils/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
SyntaxKind,
} from 'ts-morph'

export const renameEnumMember = (node: PropertyAccessExpression, to: string) => {
export const renameEnumMember = (node: PropertyAccessExpression, to: string | number) => {
const ancestor = node.getFirstAncestor()

if (ancestor?.isKind(SyntaxKind.JsxExpression)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,12 @@ import {
import { Avatar } from '~/src/components/Avatar'

import { AvatarGroup } from './AvatarGroup'
import {
AvatarGroupEllipsisType,
type AvatarGroupProps,
} from './AvatarGroup.types'
import { type AvatarGroupProps } from './AvatarGroup.types'
import MOCK_AVATAR_LIST from './__mocks__/avatarList'

const meta: Meta<typeof AvatarGroup> = {
component: AvatarGroup,
argTypes: {
ellipsisType: {
control: {
type: 'radio',
},
options: AvatarGroupEllipsisType,
},
max: {
control: {
type: 'range',
Expand Down Expand Up @@ -64,7 +55,7 @@ export const Primary: StoryObj<AvatarGroupProps> = {
args: {
max: 5,
size: '30',
ellipsisType: AvatarGroupEllipsisType.Icon,
ellipsisType: 'icon',
spacing: 4,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import {
AVATAR_GROUP_ELLIPSIS_ICON_TEST_ID,
AvatarGroup,
} from './AvatarGroup'
import {
AvatarGroupEllipsisType,
type AvatarGroupProps,
} from './AvatarGroup.types'
import { type AvatarGroupProps } from './AvatarGroup.types'
import MOCK_AVATAR_LIST from './__mocks__/avatarList'

describe('AvatarGroup', () => {
Expand All @@ -22,7 +19,7 @@ describe('AvatarGroup', () => {
props = {
max: MOCK_AVATAR_LIST.length - 1,
spacing: 4,
ellipsisType: AvatarGroupEllipsisType.Icon,
ellipsisType: 'icon',
}
})

Expand All @@ -45,7 +42,7 @@ describe('AvatarGroup', () => {

describe('Ellipsis type - Icon', () => {
beforeEach(() => {
props.ellipsisType = AvatarGroupEllipsisType.Icon
props.ellipsisType = 'icon'
})

it('Snapshot', () => {
Expand All @@ -70,7 +67,7 @@ describe('AvatarGroup', () => {

describe('Ellipsis type - Count', () => {
beforeEach(() => {
props.ellipsisType = AvatarGroupEllipsisType.Count
props.ellipsisType = 'count'
})

it('Snapshot', () => {
Expand Down
34 changes: 14 additions & 20 deletions packages/bezier-react/src/components/AvatarGroup/AvatarGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@ import {
type AvatarSize,
useAvatarRadiusToken,
} from '~/src/components/Avatar'
import {
Icon,
IconSize,
} from '~/src/components/Icon'
import { Icon } from '~/src/components/Icon'
import { Text } from '~/src/components/Text'

import {
AvatarGroupEllipsisType,
type AvatarGroupProps,
} from './AvatarGroup.types'
import { type AvatarGroupProps } from './AvatarGroup.types'

import styles from './AvatarGroup.module.scss'

Expand All @@ -41,14 +35,14 @@ function getRestAvatarListCountText(count: number, max: number) {
// TODO: Not specified
function getProperIconSize(avatarSize: AvatarSize) {
return {
20: IconSize.XXS,
24: IconSize.XS,
30: IconSize.S,
36: IconSize.Normal,
42: IconSize.Normal,
48: IconSize.L,
90: IconSize.L,
120: IconSize.L,
20: 'xxs',
24: 'xs',
30: 's',
36: 'normal',
42: 'normal',
48: 'l',
90: 'l',
120: 'l',
}[avatarSize]
}

Expand All @@ -74,7 +68,7 @@ function getProperTypoSize(avatarSize: AvatarSize) {
* <AvatarGroup
* max={2}
* spacing={4}
* ellipsisType={AvatarGroupEllipsisType.Icon}
* ellipsisType="icon"
* >
* <Avatar />
* <Avatar />
Expand All @@ -86,7 +80,7 @@ export const AvatarGroup = forwardRef<HTMLDivElement, AvatarGroupProps>(function
max,
size = '24',
spacing = AVATAR_GROUP_DEFAULT_SPACING,
ellipsisType = AvatarGroupEllipsisType.Icon,
ellipsisType = 'icon',
onMouseEnterEllipsis,
onMouseLeaveEllipsis,
style,
Expand Down Expand Up @@ -132,7 +126,7 @@ export const AvatarGroup = forwardRef<HTMLDivElement, AvatarGroupProps>(function
return AvatarElement
}

if (ellipsisType === AvatarGroupEllipsisType.Icon) {
if (ellipsisType === 'icon') {
return (
<div
key="ellipsis"
Expand All @@ -157,7 +151,7 @@ export const AvatarGroup = forwardRef<HTMLDivElement, AvatarGroupProps>(function
)
}

if (ellipsisType === AvatarGroupEllipsisType.Count) {
if (ellipsisType === 'count') {
return (
<React.Fragment key="ellipsis">
{ AvatarElement }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import type {

import { type AvatarSize } from '~/src/components/Avatar'

export enum AvatarGroupEllipsisType {
Icon = 'Icon',
Count = 'Count',
}
export type AvatarGroupEllipsisType =
| 'icon'
| 'count'

type MouseEventHandler = React.MouseEventHandler<HTMLDivElement>

Expand All @@ -31,7 +30,7 @@ interface AvatarGroupOwnProps {

/**
* Controls how the ellipsis is displayed.
* @default AvatarGroupEllipsisType.Icon
* @default 'icon'
*/
ellipsisType?: AvatarGroupEllipsisType

Expand Down
2 changes: 1 addition & 1 deletion packages/bezier-react/src/components/AvatarGroup/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { AvatarGroup } from './AvatarGroup'
export {
AvatarGroupEllipsisType,
type AvatarGroupEllipsisType,
type AvatarGroupProps,
} from './AvatarGroup.types'
Loading
Loading