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

chore(PPDSC-1852): replace enums #340

Merged
merged 62 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
75b2060
chore(PPDSC-1852): chore-ppdse-1852-replace buttonSize with union
baburay23 Aug 18, 2022
cf2a7bf
chore(PPDSC-1852): chore-ppdse-1852-replace buttonSize with union
baburay23 Aug 18, 2022
5404111
chore(PPDSC-1852): chore-ppdse-1852-replace buttonSize with union
Aug 18, 2022
068251d
chore(PPDSC-1852): chore-ppdse-1852-replace-buttonSize-with-union
Aug 18, 2022
84b3ea3
chore(PPDSC-1852): chore-ppdse-1852-replace-buttonSize-with-union
Aug 18, 2022
ba21f69
chore(PPDSC-1852): chore-ppdse-1852-replace-menuItemAlign-with-union
Aug 22, 2022
345eb64
chore(PPDSC-1852): chore-ppdse-1852-replace-buttonSize-with-union
Aug 22, 2022
ef2ff98
chore(PPDSC-1852): chore-ppdse-1852-fixed audioplayer type
baburay23 Aug 22, 2022
d82cf97
chore(PPDSC-1852): chore-ppdse-1852-fixed audioplayer type
baburay23 Aug 22, 2022
c5c2081
chore(PPDSC-1852): chore-ppdse-1852-removed stackChild enum
baburay23 Aug 22, 2022
3fbca89
chore(PPDSC-1852): chore-ppdse-1852-removed stackChild enum
baburay23 Aug 22, 2022
78e2f1f
chore(PPDSC-1852): removed Tagsize labelPosition enum
Aug 22, 2022
b6c896d
chore(PPDSC-1852): chore-ppdse-1852-updated slider labelposition
baburay23 Aug 22, 2022
3235183
chore(PPDSC-1852): chore-ppdse-1852-updated src files for flow
baburay23 Aug 22, 2022
316ce2e
chore(PPDSC-1852): chore-ppdse-1852-updated slider test
baburay23 Aug 22, 2022
2eba3aa
chore(PPDSC-1852): removed Tagsize labelPosition enum
Aug 22, 2022
a5cfb87
chore(PPDSC-1852): removed Tagsize tabIndicatorPosition enum
Aug 22, 2022
b9f2cbc
chore(PPDSC-1852): removed MenuItemSize enum
Aug 23, 2022
8b01622
chore(PPDSC-1852): removed TabAlign enum
Aug 23, 2022
bc37b1b
chore(PPDSC-1852): removed tabSize enum
Aug 23, 2022
39b2b5d
chore(PPDSC-1852): chore-ppdse-1852-removed flow and stackD
baburay23 Aug 23, 2022
b56fc0f
chore(PPDSC-1852): chore-ppdse-1852-stack test passing
baburay23 Aug 23, 2022
b890549
chore(PPDSC-1852): chore-ppdse-1852-stack test passing
baburay23 Aug 23, 2022
1b9d7b7
chore(PPDSC-1852): chore-ppdse-1852-tab align removed
baburay23 Aug 23, 2022
ef2e33d
chore(PPDSC-1852): chore-ppdse-1852-got rid of tab enums
baburay23 Aug 23, 2022
e1329ee
chore(PPDSC-1852): chore-ppdse-1852-got rid of tab enums
baburay23 Aug 23, 2022
1384495
chore(PPDSC-1852): chore-ppdse-1852-flagsize done
baburay23 Aug 23, 2022
94fed7d
chore(PPDSC-1852): chore-ppdse-1852-buttonsize removed
baburay23 Aug 23, 2022
6c39304
chore(PPDSC-1852): chore-ppdse-1852-updated documentation
baburay23 Aug 23, 2022
996f3c4
chore(PPDSC-1852): chore-ppdse-1852-updated tab documentation
baburay23 Aug 23, 2022
c3c17e9
chore(PPDSC-1852): chore-ppdse-1852-tests updated
baburay23 Aug 23, 2022
53f8fa5
chore(PPDSC-1852): chore-ppdse-1852-fixed tag size
baburay23 Aug 23, 2022
19f5be2
chore(PPDSC-1852): chore-ppdse-1852-menu align moved
baburay23 Aug 23, 2022
1d53a15
chore(PPDSC-1852): chore-ppdse-1852-tidied menu tests
baburay23 Aug 23, 2022
650a539
chore(PPDSC-1852): chore-ppdse-1852-fixed stack test types
baburay23 Aug 23, 2022
0c32d80
chore(PPDSC-1852): removed TabsDistribution enum
Aug 24, 2022
93cab11
chore(PPDSC-1852): chore-ppdse-1852-fixed stack test types
baburay23 Aug 24, 2022
621b3e5
chore(PPDSC-1852): chore-ppdse-1852-fixed menu test
baburay23 Aug 24, 2022
49740bf
chore(PPDSC-1852): chore-ppdse-1852-fixed slider.mdx
baburay23 Aug 24, 2022
dc86914
chore(PPDSC-1852): removed TabsDistribution enum
Aug 24, 2022
c46037e
chore(PPDSC-1852): chore-ppdse-1852-textfiedl done
baburay23 Aug 24, 2022
3383e5b
chore(PPDSC-1852): chore-ppdse-1852-textinput done
baburay23 Aug 24, 2022
2cf70f6
chore(PPDSC-1852): chore-ppdse-1852-textinput done
baburay23 Aug 24, 2022
7300e41
chore(PPDSC-1852): chore-ppdse-1852-tidy up
baburay23 Aug 24, 2022
53c6505
chore(PPDSC-1852): chore-ppdse-1852-fixed mdx error
baburay23 Aug 24, 2022
e813f59
chore(PPDSC-1852): chore-ppdse-1852-fixed mdx error again
baburay23 Aug 24, 2022
a9f68d8
chore(PPDSC-1852): chore-ppdse-1852-added codemod back
baburay23 Aug 24, 2022
cb3835d
chore(PPDSC-1852): chore-ppdse-1852-added codemod back and linted
baburay23 Aug 24, 2022
86c8d82
chore(PPDSC-1852): chore-ppdse-1852-sorted merge issues
baburay23 Aug 25, 2022
8d4e9c6
chore(PPDSC-1852): chore-ppdse-1852-fixed merge
baburay23 Aug 25, 2022
f785d48
chore(PPDSC-1852): chore-ppdse-1852-fixed stack story
baburay23 Aug 25, 2022
6aa8eaa
chore(PPDSC-1852): chore-ppdse-1852-tidied audioplayer types
baburay23 Aug 25, 2022
107a4a7
chore(PPDSC-1852): chore-ppdse-1852-changed to lower case
baburay23 Aug 25, 2022
ec84e19
chore(PPDSC-1852): chore-ppdse-1852-fixed comments
baburay23 Aug 25, 2022
5bc4282
fix(PPDSC-1852): add lowercase with space to enum codemod
Xin00163 Aug 25, 2022
2189d7b
chore(PPDSC-1852): chore-ppdse-1852-fixed stack types
baburay23 Aug 25, 2022
2ef0f8f
chore(PPDSC-1852): chore-ppdse-1852-sorted merge conflicts
baburay23 Aug 25, 2022
0f4469c
chore(PPDSC-1852): chore-ppdse-1852-updated tests
baburay23 Aug 25, 2022
68e558a
Merge branch 'main' into chore/PPDSC-1852-replace-enums
baburay23 Aug 25, 2022
a5e4054
chore(PPDSC-1852): chore-ppdse-1852-updated stack.mdx
baburay23 Aug 25, 2022
6eebf2f
chore(PPDSC-1852): chore-ppdse-1852-updated stack.mdx
baburay23 Aug 25, 2022
6b42eb2
Merge branch 'main' into chore/PPDSC-1852-replace-enums
baburay23 Aug 26, 2022
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
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
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