Skip to content

Commit e378004

Browse files
authored
fix: Handful of fixes based on v3 migration. (#332)
* Fix codemods. * Fix generics. * Move prop. * Ignore withIcon.
1 parent 9fe10a6 commit e378004

File tree

16 files changed

+32
-23
lines changed

16 files changed

+32
-23
lines changed

codemods/v3/canonicalPropsState.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ module.exports = function canonicalPropsState(
1515
mod.source.find(mod.cs.ImportDeclaration).forEach(({ node }) => {
1616
const source = String(node.source.value);
1717

18-
if (!source.includes('lunar') && !source.includes('components')) {
18+
if (
19+
(!source.includes('lunar') && !source.includes('components')) ||
20+
source.endsWith('withIcon')
21+
) {
1922
return;
2023
}
2124

codemods/v3/i18nKeyContext.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ module.exports = function i18nKeyContext(
3232
callee: { object: { name: 'T' }, property: { name: 'phrase' } },
3333
})
3434
.forEach(({ node }) => {
35-
const [, params, opts] = node.arguments;
35+
const [phrase, params, opts] = node.arguments;
3636
let key = '';
3737

38+
// Already converted
39+
if (phrase?.type === 'StringLiteral' && params?.type === 'StringLiteral') {
40+
return;
41+
}
42+
3843
// Extract key and remove context
3944
if (opts && opts.type === 'ObjectExpression') {
4045
opts.properties = opts.properties.filter(prop => {

packages/core/src/components/CheckBox/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import BaseCheckBox, { BaseCheckBoxProps } from '../private/BaseCheckBox';
44
import FormField, { FormFieldProps, partitionFieldProps } from '../FormField';
55
import Text from '../Text';
66

7-
export type CheckBoxProps<T extends string> = BaseCheckBoxProps<T> &
7+
export type CheckBoxProps<T extends string = string> = BaseCheckBoxProps<T> &
88
FormFieldProps & {
99
/** Middle align content. */
1010
middleAlign?: boolean;

packages/core/src/components/CheckBoxController/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import proxyComponent from '../../utils/proxyComponent';
55
import FormField, { FormFieldProps, partitionFieldProps } from '../FormField';
66
import CheckBox, { CheckBoxProps } from '../CheckBox';
77

8-
export type CheckBoxControlledProps<T extends string> = Partial<
8+
export type CheckBoxControlledProps<T extends string = string> = Partial<
99
Omit<CheckBoxProps<T>, 'label' | 'value'>
1010
> & {
1111
label: NonNullable<React.ReactNode>;
1212
value: T;
1313
};
1414

15-
export type CheckBoxControllerProps<T extends string> = FormFieldProps & {
15+
export type CheckBoxControllerProps<T extends string = string> = FormFieldProps & {
1616
/** Function children in which CheckBox components can be rendered. */
1717
children: (
1818
component: React.ComponentType<CheckBoxControlledProps<T>>,
@@ -27,7 +27,7 @@ export type CheckBoxControllerProps<T extends string> = FormFieldProps & {
2727
value?: T[];
2828
};
2929

30-
export type CheckBoxControllerState<T extends string> = {
30+
export type CheckBoxControllerState<T extends string = string> = {
3131
id: string;
3232
values: Set<T>;
3333
};

packages/core/src/components/FormField/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ export type FormFieldProps = {
4444
suffix?: React.ReactNode;
4545
/** Custom style sheet. */
4646
styleSheet?: StyleSheet;
47-
/** @ignore Top align. (Internal use only) */
48-
topAlign?: boolean;
4947
};
5048

5149
export type PrivateProps = FormFieldProps & {
@@ -61,6 +59,8 @@ export type PrivateProps = FormFieldProps & {
6159
renderLargeLabel?: boolean;
6260
/** @ignore Stretches the label to 100%. */
6361
stretchLabel?: boolean;
62+
/** @ignore Top align. (Internal use only) */
63+
topAlign?: boolean;
6464
/** @ignore Middle align content. */
6565
middleAlign?: boolean;
6666
/** Custom style sheet. */

packages/core/src/components/RadioButton/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Text from '../Text';
77

88
const stateProp = mutuallyExclusiveTrueProps('checked', 'indeterminate');
99

10-
export type RadioButtonProps<T extends string> = Omit<BaseRadioButtonProps<T>, 'value'> &
10+
export type RadioButtonProps<T extends string = string> = Omit<BaseRadioButtonProps<T>, 'value'> &
1111
FormFieldProps & {
1212
/** Middle align content. */
1313
middleAlign?: boolean;

packages/core/src/components/RadioButtonController/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import proxyComponent from '../../utils/proxyComponent';
44
import FormField, { FormFieldProps, partitionFieldProps } from '../FormField';
55
import RadioButton, { RadioButtonProps } from '../RadioButton';
66

7-
export type RadioButtonControlledProps<T extends string> = Partial<
7+
export type RadioButtonControlledProps<T extends string = string> = Partial<
88
Omit<RadioButtonProps<T>, 'label' | 'value'>
99
> & {
1010
label: NonNullable<React.ReactNode>;
1111
value: T;
1212
};
1313

14-
export type RadioButtonControllerProps<T extends string> = FormFieldProps & {
14+
export type RadioButtonControllerProps<T extends string = string> = FormFieldProps & {
1515
/** Function children in which RadioButton components can be rendered. */
1616
children: (
1717
component: React.ComponentType<RadioButtonControlledProps<T>>,
@@ -26,7 +26,7 @@ export type RadioButtonControllerProps<T extends string> = FormFieldProps & {
2626
value?: T;
2727
};
2828

29-
export type RadioButtonControllerState<T extends string> = {
29+
export type RadioButtonControllerState<T extends string = string> = {
3030
id: string;
3131
value: T;
3232
};

packages/core/src/components/Select/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { v4 as uuid } from 'uuid';
33
import BaseSelect, { BaseSelectProps } from '../private/BaseSelect';
44
import FormField, { FormFieldProps, partitionFieldProps } from '../FormField';
55

6-
export type SelectProps<T extends string> = Omit<BaseSelectProps<T>, 'id'> &
6+
export type SelectProps<T extends string = string> = Omit<BaseSelectProps<T>, 'id'> &
77
FormFieldProps & {
88
/** Dropdown options. Supports `option` and `optgroup`. */
99
children: NonNullable<React.ReactNode>;

packages/core/src/components/Switch/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { v4 as uuid } from 'uuid';
33
import BaseSwitch, { BaseSwitchProps } from '../private/BaseSwitch';
44
import FormField, { FormFieldProps, partitionFieldProps } from '../FormField';
55

6-
export type SwitchProps<T extends string> = Omit<BaseSwitchProps<T>, 'id'> & FormFieldProps;
6+
export type SwitchProps<T extends string = string> = Omit<BaseSwitchProps<T>, 'id'> &
7+
FormFieldProps;
78

89
/** A controlled switch (fancy checkbox) field. */
910
export default function Switch<T extends string = string>(props: SwitchProps<T>) {

packages/core/src/components/Tabs/Tab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import TrackingBoundary from '../TrackingBoundary';
66
import { styleSheetTab } from './styles';
77
import useStyles, { StyleSheet } from '../../hooks/useStyles';
88

9-
export type TabProps<T extends string> = Pick<
9+
export type TabProps<T extends string = string> = Pick<
1010
ButtonOrLinkProps,
1111
'afterIcon' | 'beforeIcon' | 'disabled' | 'href'
1212
> & {

0 commit comments

Comments
 (0)