Skip to content

Commit

Permalink
chore(PPDSC-1852): replace enums (#340)
Browse files Browse the repository at this point in the history
* chore(PPDSC-1852): chore-ppdse-1852-replace buttonSize with union

* chore(PPDSC-1852): chore-ppdse-1852-replace buttonSize with union

* chore(PPDSC-1852): chore-ppdse-1852-replace buttonSize with union

* chore(PPDSC-1852): chore-ppdse-1852-replace-buttonSize-with-union

* chore(PPDSC-1852): chore-ppdse-1852-replace-buttonSize-with-union

* chore(PPDSC-1852): chore-ppdse-1852-replace-menuItemAlign-with-union

* chore(PPDSC-1852): chore-ppdse-1852-replace-buttonSize-with-union

* chore(PPDSC-1852): chore-ppdse-1852-fixed audioplayer type

* chore(PPDSC-1852): chore-ppdse-1852-removed stackChild enum

* chore(PPDSC-1852): chore-ppdse-1852-removed stackChild enum

* chore(PPDSC-1852): removed Tagsize labelPosition enum

* chore(PPDSC-1852): chore-ppdse-1852-updated slider labelposition

* chore(PPDSC-1852): chore-ppdse-1852-updated src files for flow

* chore(PPDSC-1852): chore-ppdse-1852-updated slider test

* chore(PPDSC-1852): removed Tagsize tabIndicatorPosition enum

* chore(PPDSC-1852): removed MenuItemSize enum

* chore(PPDSC-1852): removed TabAlign enum

* chore(PPDSC-1852): removed tabSize enum

* chore(PPDSC-1852): chore-ppdse-1852-removed flow and stackD

* chore(PPDSC-1852): chore-ppdse-1852-stack test passing

* chore(PPDSC-1852): chore-ppdse-1852-tab align removed

* chore(PPDSC-1852): chore-ppdse-1852-got rid of tab enums

* chore(PPDSC-1852): chore-ppdse-1852-got rid of tab enums

* chore(PPDSC-1852): chore-ppdse-1852-flagsize done

* chore(PPDSC-1852): chore-ppdse-1852-buttonsize removed

* chore(PPDSC-1852): chore-ppdse-1852-updated documentation

* chore(PPDSC-1852): chore-ppdse-1852-updated tab documentation

* chore(PPDSC-1852): chore-ppdse-1852-tests updated

* chore(PPDSC-1852): chore-ppdse-1852-fixed tag size

* chore(PPDSC-1852): chore-ppdse-1852-menu align moved

* chore(PPDSC-1852): chore-ppdse-1852-tidied menu tests

* chore(PPDSC-1852): chore-ppdse-1852-fixed stack test types

* chore(PPDSC-1852): removed TabsDistribution enum

* chore(PPDSC-1852): chore-ppdse-1852-fixed menu test

* chore(PPDSC-1852): chore-ppdse-1852-fixed slider.mdx

* chore(PPDSC-1852): chore-ppdse-1852-textfiedl done

* chore(PPDSC-1852): chore-ppdse-1852-textinput done

* chore(PPDSC-1852): chore-ppdse-1852-textinput done

* chore(PPDSC-1852): chore-ppdse-1852-tidy up

* chore(PPDSC-1852): chore-ppdse-1852-fixed mdx error

* chore(PPDSC-1852): chore-ppdse-1852-fixed mdx error again

* chore(PPDSC-1852): chore-ppdse-1852-added codemod back

* chore(PPDSC-1852): chore-ppdse-1852-added codemod back and linted

* chore(PPDSC-1852): chore-ppdse-1852-fixed merge

* chore(PPDSC-1852): chore-ppdse-1852-fixed stack story

* chore(PPDSC-1852): chore-ppdse-1852-tidied audioplayer types

* chore(PPDSC-1852): chore-ppdse-1852-changed to lower case

* chore(PPDSC-1852): chore-ppdse-1852-fixed comments

* fix(PPDSC-1852): add lowercase with space to enum codemod

* chore(PPDSC-1852): chore-ppdse-1852-fixed stack types

* chore(PPDSC-1852): chore-ppdse-1852-updated tests

* chore(PPDSC-1852): chore-ppdse-1852-updated stack.mdx

Co-authored-by: Ravindren <[email protected]>
Co-authored-by: Xin00163 <[email protected]>
  • Loading branch information
3 people authored Aug 26, 2022
1 parent 7f5f770 commit 1c7d0dd
Show file tree
Hide file tree
Showing 131 changed files with 2,188 additions and 2,503 deletions.
4 changes: 2 additions & 2 deletions README_COMPONENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ NewsKit components can be used like any typical react components. One thing to b
The following example shows the "Hello World!" example of using a NewsKit component. More comprehensive usage documentation can be found on our [website](https://www.newskit.co.uk/getting-started/code/engineering-quickstart/).

```typescript
import {ThemeProvider, Tag, TagSize, newskitLightTheme} from 'newskit';
import {ThemeProvider, Tag, newskitLightTheme} from 'newskit';
import React from 'react';

export default class App extends React.Component {
Expand All @@ -88,7 +88,7 @@ export default class App extends React.Component {
<ThemeProvider theme={newskitLightTheme}>
<Tag
href="http://example.com"
size={TagSize.Medium}>
size="medium">
Tag Content
</Tag>
</ThemeProvider>
Expand Down
24 changes: 19 additions & 5 deletions lib/codemod/src/transforms/__tests__/enums-to-union/actual.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import {
const Component = () => (
<>
<Button size={ButtonSize.Small}>Button</Button>
<IconButton size={ButtonSize.Small}><IconFilledLight overrides={{size: 'iconSize010'}} /></IconButton>
<IconButton size={ButtonSize.Small}>
<IconFilledLight overrides={{size: 'iconSize010'}} />
</IconButton>
<Menu vertical align={MenuItemAlign.Start} size={MenuItemSize.Small}>
<MenuItem href={href}>Menu item knickknackatory 1</MenuItem>
<MenuItem href={href}>Menu item knickknackatory 2</MenuItem>
Expand Down Expand Up @@ -57,6 +59,18 @@ const Component = () => (
<StackChild alignSelf={AlignSelfValues.Stretch}>
<Divider />
</StackChild>
<StackChild alignSelf={AlignSelfValues.FirstBaseline}>
<Divider />
</StackChild>
<StackChild alignSelf={AlignSelfValues.LastBaseline}>
<Divider />
</StackChild>
<StackChild alignSelf={AlignSelfValues.SafeCenter}>
<Divider />
</StackChild>
<StackChild alignSelf={AlignSelfValues.UnsafeCenter}>
<Divider />
</StackChild>
<Tag size={TagSize.Medium}>Tag</Tag>
<Tabs
size={TabSize.Medium}
Expand All @@ -65,9 +79,7 @@ const Component = () => (
indicatorPosition={TabsIndicatorPosition.Start}
distribution={TabsDistribution.Equal}
>
<Tab label="Tab">
Tab
</Tab>
<Tab label="Tab">Tab</Tab>
</Tabs>
<Label size={TextFieldSize.Small}>Label</Label>
<Form onSubmit={onSubmit}>
Expand All @@ -82,7 +94,9 @@ const Component = () => (
assistiveText="Your email"
/>
</Form>
<Avatar size={AvatarSize.Small} align={AlignContent.Start}>New image</Avatar>
<Avatar size={AvatarSize.Small} align={AlignContent.Start}>
New image
</Avatar>
<ArticleHeader align={HeaderAlign.Start}>Header</ArticleHeader>
</>
);
24 changes: 19 additions & 5 deletions lib/codemod/src/transforms/__tests__/enums-to-union/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import {
const Component = () => (
<>
<Button size="small">Button</Button>
<IconButton size="small"><IconFilledLight overrides={{size: 'iconSize010'}} /></IconButton>
<IconButton size="small">
<IconFilledLight overrides={{size: 'iconSize010'}} />
</IconButton>
<Menu vertical align="start" size="small">
<MenuItem href={href}>Menu item knickknackatory 1</MenuItem>
<MenuItem href={href}>Menu item knickknackatory 2</MenuItem>
Expand Down Expand Up @@ -43,6 +45,18 @@ const Component = () => (
<StackChild alignSelf="stretch">
<Divider />
</StackChild>
<StackChild alignSelf="first baseline">
<Divider />
</StackChild>
<StackChild alignSelf="last baseline">
<Divider />
</StackChild>
<StackChild alignSelf="safe center">
<Divider />
</StackChild>
<StackChild alignSelf="unsafe center">
<Divider />
</StackChild>
<Tag size="medium">Tag</Tag>
<Tabs
size="medium"
Expand All @@ -51,9 +65,7 @@ const Component = () => (
indicatorPosition="start"
distribution="equal"
>
<Tab label="Tab">
Tab
</Tab>
<Tab label="Tab">Tab</Tab>
</Tabs>
<Label size="small">Label</Label>
<Form onSubmit={onSubmit}>
Expand All @@ -68,7 +80,9 @@ const Component = () => (
assistiveText="Your email"
/>
</Form>
<Avatar size={AvatarSize.Small} align={AlignContent.Start}>New image</Avatar>
<Avatar size={AvatarSize.Small} align={AlignContent.Start}>
New image
</Avatar>
<ArticleHeader align={HeaderAlign.Start}>Header</ArticleHeader>
</>
);
16 changes: 13 additions & 3 deletions lib/codemod/src/transforms/enum-to-union.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const {toKebabCase} = require('../utils/to-kebab-case');
const {toLowerCaseWithSpace} = require('../utils/to-lower-case-with-space');

const enumNames = [
'ButtonSize',
Expand Down Expand Up @@ -61,12 +62,21 @@ const transformEnums = (j, root) => {
.filter(path => enumNames.includes(path.value.expression.object.name))
.replaceWith(path => {
const propValue = path.value.expression.property.name;
const newPropValue = `${toKebabCase(propValue)}`;
const newPropValue =
propName === 'alignSelf' &&
[
'FirstBaseline',
'LastBaseline',
'SafeCenter',
'UnsafeCenter',
].includes(propValue)
? `${toLowerCaseWithSpace(propValue)}`
: `${toKebabCase(propValue)}`;
const newPath =
propName === 'stackDistribution' &&
['start', 'end'].includes(newPropValue)
? j.literal(`flex-${toKebabCase(propValue)}`)
: j.literal(`${toKebabCase(propValue)}`);
? j.literal(`flex-${newPropValue}`)
: j.literal(`${newPropValue}`);
return newPath;
});
});
Expand Down
10 changes: 10 additions & 0 deletions lib/codemod/src/utils/__tests__/to-lower-case-with-space.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const {toLowerCaseWithSpace} = require('../to-lower-case-with-space');

describe('to-lower-case-with-space', () => {
test('toLowerCaseWithSpace', () => {
expect(toLowerCaseWithSpace('HelloWorld')).toBe('hello world');
expect(toLowerCaseWithSpace('Hello World')).toBe('hello world');
expect(toLowerCaseWithSpace('HelloWorldAgain')).toBe('hello world again');
expect(toLowerCaseWithSpace('HelloWorldcup')).toBe('hello worldcup');
});
});
11 changes: 11 additions & 0 deletions lib/codemod/src/utils/to-lower-case-with-space.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function toLowerCaseWithSpace(str) {
if (str) {
return str.replace(/([a-z])([A-Z])/g, '$1 $2').toLowerCase();
}
/* istanbul ignore next */
return '';
}

module.exports = {
toLowerCaseWithSpace,
};
4 changes: 2 additions & 2 deletions site/components/component-api/component-api.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {Block, Tab, Tabs, TabSize} from 'newskit';
import {Block, Tab, Tabs} from 'newskit';
import {Table} from '../table';
import {ContentText} from '../text-section/content-text';
import {ComponentAPIProps} from './types';
Expand Down Expand Up @@ -107,7 +107,7 @@ export const ComponentAPI: React.FC<ComponentAPIProps> = ({components}) => (
</ContentText>
)}
{tabs.length > 1 && (
<Tabs size={TabSize.Medium}>
<Tabs size="medium">
{tabs.map(({label, tabSummary, content}) => (
<Tab label={label} overrides={tabOverrides} key={label}>
{tabSummary && <ContentText>{tabSummary}</ContentText>}
Expand Down
10 changes: 4 additions & 6 deletions site/components/feature-card/feature-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import React from 'react';
import {
Block,
Visible,
StackDistribution,
Stack,
Headline,
TextBlock,
Button,
ButtonSize,
useTheme,
toNewsKitIcon,
} from 'newskit';
Expand Down Expand Up @@ -154,7 +152,7 @@ const FeatureCardHorizontal = React.forwardRef<
<Block spaceStack="space020">
<OptionalButtonLinkWrapper href={href} buttonHref={buttonHref}>
<Button
size={ButtonSize.Small}
size="small"
overrides={{
stylePreset: `${stylePrefix}Button`,
typographyPreset: 'utilityButton010',
Expand Down Expand Up @@ -188,7 +186,7 @@ const FeatureCardHorizontal = React.forwardRef<
},
}}
>
<Stack stackDistribution={StackDistribution.Center}>
<Stack stackDistribution="center">
{title && (
<Block spaceStack={{xs: 'space045', lg: 'space050'}}>
<Headline
Expand Down Expand Up @@ -216,7 +214,7 @@ const FeatureCardHorizontal = React.forwardRef<
{buttonLabel && (
<OptionalButtonLinkWrapper href={href} buttonHref={buttonHref}>
<Button
size={ButtonSize.Small}
size="small"
overrides={{
stylePreset: `${stylePrefix}Button`,
typographyPreset: 'utilityButton010',
Expand Down Expand Up @@ -317,7 +315,7 @@ const FeatureCardVertical = React.forwardRef<HTMLDivElement, FeatureCardProps>(
<Block spaceStack="space020">
<OptionalButtonLinkWrapper href={href} buttonHref={buttonHref}>
<Button
size={ButtonSize.Small}
size="small"
overrides={{
stylePreset: `${stylePrefix}Button`,
typographyPreset: 'utilityButton010',
Expand Down
4 changes: 2 additions & 2 deletions site/components/meta/figma-button.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import {Button, ButtonSize} from 'newskit';
import {Button} from 'newskit';

import {IconFilledFigma} from '../icons/icon-filled-figma';

export const FigmaButton: React.FC<{href?: string}> = ({href}) =>
href ? (
<Button
size={ButtonSize.Small}
size="small"
overrides={{
typographyPreset: 'utilityButton010',
stylePreset: 'buttonOutlinedSecondary',
Expand Down
4 changes: 2 additions & 2 deletions site/components/meta/github-button.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import {Button, ButtonSize} from 'newskit';
import {Button} from 'newskit';

import {IconFilledGitHub} from '../icons/icon-filled-github';

export const GitHubButton: React.FC<{href?: string}> = ({href}) =>
href ? (
<Button
size={ButtonSize.Small}
size="small"
overrides={{
typographyPreset: 'utilityButton010',
stylePreset: 'buttonOutlinedSecondary',
Expand Down
4 changes: 2 additions & 2 deletions site/components/meta/introduce.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {Headline, Stack, Flow, TextBlock} from 'newskit';
import {Headline, Stack, TextBlock} from 'newskit';
import {Link} from '../link';

const newskitRepoLink = `https://github.com/newscorp-ghfb/newskit/releases/tag/`;
Expand All @@ -9,7 +9,7 @@ export const Introduced: React.FC<{
introducedLink?: boolean;
}> = ({introduced, introducedLink}) =>
introduced ? (
<Stack flow={Flow.VerticalLeft} spaceInline="space050">
<Stack flow="vertical-left" spaceInline="space050">
<Headline overrides={{typographyPreset: 'utilityLabel020'}}>
Introduced
</Headline>
Expand Down
30 changes: 10 additions & 20 deletions site/components/meta/meta.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import React from 'react';
import {
Stack,
Block,
Divider,
StackChild,
AlignSelfValues,
Flow,
Hidden,
Cell,
Grid,
} from 'newskit';
import {Stack, Block, Divider, StackChild, Hidden, Cell, Grid} from 'newskit';
import {MetaProps} from './types';
import {GitHubButton} from './github-button';
import {FigmaButton} from './figma-button';
Expand All @@ -26,10 +16,10 @@ export const Meta = ({
<>
<Block spaceStack={{xs: 'space080', md: 'space050'}}>
<Hidden xs sm>
<Stack flow={Flow.HorizontalCenter} stackDistribution="space-between">
<Stack flow={Flow.HorizontalTop}>
<Stack flow="horizontal-center" stackDistribution="space-between">
<Stack flow="horizontal-top">
<Status status={status} />
<StackChild alignSelf={AlignSelfValues.Stretch}>
<StackChild alignSelf="stretch">
<Block
spaceInline={{
md: 'space060',
Expand All @@ -48,7 +38,7 @@ export const Meta = ({
/>
</Stack>
<Stack flow="horizontal-center" spaceInline="space040">
<StackChild alignSelf={AlignSelfValues.Stretch}>
<StackChild alignSelf="stretch">
<GitHubButton href={codeUrl} />
</StackChild>
<FigmaButton href={figmaUrl} />
Expand All @@ -59,17 +49,17 @@ export const Meta = ({
</Hidden>

<Hidden md lg xl>
<Stack flow={Flow.VerticalLeft} spaceInline="space050">
<StackChild alignSelf={AlignSelfValues.Stretch}>
<Stack flow="vertical-left" spaceInline="space050">
<StackChild alignSelf="stretch">
<Cell xs={6}>
<Status status={status} />
</Cell>
<Cell xs={6}>
<Stack flow={Flow.HorizontalTop}>
<Stack flow="horizontal-top">
<Divider vertical />
<Block spaceInline="space060" />
<Stack
flow={Flow.VerticalLeft}
flow="vertical-left"
spaceInline="space020"
stackDistribution="space-evenly"
/>
Expand All @@ -80,7 +70,7 @@ export const Meta = ({
</Stack>
</Cell>
</StackChild>
<StackChild alignSelf={AlignSelfValues.Stretch}>
<StackChild alignSelf="stretch">
<Grid xsMargin="space000">
<Cell xs={12}>
<Divider />
Expand Down
6 changes: 3 additions & 3 deletions site/components/meta/status.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react';
import {Block, Flag, FlagSize, Flow, Headline, Stack, TextBlock} from 'newskit';
import {Block, Flag, Headline, Stack, TextBlock} from 'newskit';
import {MetaFlagStylePresets} from './types';

export const Status: React.FC<{status?: string}> = ({status}) =>
status ? (
<Stack flow={Flow.VerticalLeft} spaceInline="space040">
<Stack flow="vertical-left" spaceInline="space040">
<Headline overrides={{typographyPreset: 'utilityLabel020'}}>
Status
</Headline>
<Flag
size={FlagSize.Small}
size="small"
overrides={{
stylePreset: MetaFlagStylePresets.Supported,
}}
Expand Down
4 changes: 2 additions & 2 deletions site/components/playground/code-example.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import CodeSandboxer from 'react-codesandboxer';
import {Button, ButtonSize} from 'newskit';
import {Button} from 'newskit';
import {Code} from '../code';
import {LegacyBlock} from '../legacy-block';
import {ErrorMessageContainer} from './error-boundary';
Expand Down Expand Up @@ -78,7 +78,7 @@ export const CodeExample: React.FC<CodeExampleProps> = ({
<LegacyBlock alignSelf="flex-end" padding="sizing060">
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<a>
<Button size={ButtonSize.Medium} data-testid="code-sandbox">
<Button size="medium" data-testid="code-sandbox">
Edit on CodeSandbox
</Button>
</a>
Expand Down
Loading

0 comments on commit 1c7d0dd

Please sign in to comment.