Skip to content

Commit

Permalink
Autogenerate sidebar names using getTitle function
Browse files Browse the repository at this point in the history
  • Loading branch information
StraightOuttaCrompton authored and MargeBot committed Aug 18, 2021
1 parent 55d96a8 commit da04754
Show file tree
Hide file tree
Showing 40 changed files with 157 additions and 134 deletions.
5 changes: 5 additions & 0 deletions applications/storybook/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ module.exports = {
chunkFilename: isProduction ? '[id].[contenthash:8].css' : '[id].css',
}),
],
node: {
...config.node,
__dirname: true,
__filename: true,
},
};
},
};
23 changes: 23 additions & 0 deletions applications/storybook/src/helpers/title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import _startcase from 'lodash.startcase';

const caseString = (str: string, caseFilename: boolean = true) => {
// avoid _startcase stripping the '/'
return str
.split('/')
.map((item, index, arr) => {
if (!caseFilename && index === arr.length - 1) {
return item;
}

return _startcase(item);
})
.join('/');
};

export const getTitle = (filename: string, caseFilename?: boolean) => {
const directoryPrefix = 'src/stories/';
const storySuffix = /.stories.(tsx|mdx)/;
const strippedFileName = filename.replace(directoryPrefix, '').replace(storySuffix, '');

return caseString(strippedFileName, caseFilename);
};
4 changes: 2 additions & 2 deletions applications/storybook/src/stories/Changelog.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meta, Description } from '@storybook/addon-docs/blocks';

import { getTitle } from '../helpers/title';
import changelog from '../../CHANGELOG.md';

<Meta title="Changelog" />
<Meta title={getTitle(__filename)} />

<Description>{changelog}</Description>
18 changes: 9 additions & 9 deletions applications/storybook/src/stories/Introduction.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Meta } from '@storybook/addon-docs/blocks';
import { getTitle } from '../helpers/title';

<Meta title="Introduction" />
<Meta title={getTitle(__filename)} />

# Proton Storybook


Welcome to ProtonMail Design System. The goals of these pages are:

- Having a more consistent experience for users
- Having a consistent reference for all the teams
- Improving/simplifying work discussions between design and devs, and between all front-end team (same language, same conventions, same objectives)
- Improving/simplifying Front-End maintenability/scalability
- Avoid reinventing the wheel for Front-End
- Documentaaaation! Because it is important. ©
- Facilitating the onboarding of newcomers in the team.
- Having a more consistent experience for users
- Having a consistent reference for all the teams
- Improving/simplifying work discussions between design and devs, and between all front-end team (same language, same conventions, same objectives)
- Improving/simplifying Front-End maintenability/scalability
- Avoid reinventing the wheel for Front-End
- Documentaaaation! Because it is important. ©
- Facilitating the onboarding of newcomers in the team.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Alert } from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './Alert.mdx';

export default {
component: Alert,
title: 'Components / Alert',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import {
Marks,
Icon,
} from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './Autocomplete.mdx';

export default {
title: 'Components / Autocomplete',
title: getTitle(__filename, false),
component: Autocomplete,
parameters: {
docs: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Badge } from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './Badge.mdx';

export default {
component: Badge,
title: 'Components / Badge',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import {
ButtonLike,
Checkbox,
} from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './Button.mdx';

export default {
component: Button,
title: 'Components / Button',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
4 changes: 2 additions & 2 deletions applications/storybook/src/stories/components/ButtonGroup.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Canvas, Story, ArgsTable, Primary, PRIMARY_STORY } from "@storybook/addon-docs/blocks";

# Button group
# ButtonGroup

The button group is a simply a group of ButtonLike components.
The button group is simply a group of ButtonLike components.

<Canvas>
<Story id="components-button-group--sandbox" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import {
RadioGroup,
ButtonGroup,
} from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './ButtonGroup.mdx';

export default {
component: ButtonGroup,
title: 'Components / Button Group',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Button, Card } from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './Card.mdx';

export default {
component: Card,
title: 'Components / Card',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Copy } from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './Copy.mdx';

export default {
component: Copy,
title: 'Components / Copy',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Countdown } from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './Countdown.mdx';

export default {
component: Countdown,
title: 'Components / Countdown',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useMemo, useState } from 'react';
import { DateInput } from '@proton/components';
import { addDays } from '@proton/shared/lib/date-fns-utc';
import { getTitle } from '../../helpers/title';

import mdx from './DateInput.mdx';

export default {
component: DateInput,
title: 'Components / DateInput',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useState } from 'react';
import { Dropzone, Button } from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './Dropzone.mdx';

export default {
component: Dropzone,
title: 'Components / Dropzone',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { useState } from 'react';
import * as React from 'react';
import { InputButton } from '@proton/components';
import { remove } from '@proton/shared/lib/helpers/array';
import { getTitle } from '../../helpers/title';

import mdx from './InputButton.mdx';

export default {
component: InputButton,
title: 'Components / InputButton',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useState } from 'react';
import { Icon, InputFieldTwo, PasswordInputTwo } from '@proton/components';
import mdx from './InputField.mdx';
import { getTitle } from '../../helpers/title';

import mdx from './InputFieldTwo.mdx';

export default {
component: InputFieldTwo,
title: 'Components / InputFieldTwo',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { useState } from 'react';
import * as React from 'react';
import { InputTwo } from '@proton/components';
import ccIcon from '@proton/styles/assets/img/credit-card-icons/cc-master.svg';
import mdx from './Input.mdx';
import { getTitle } from '../../helpers/title';

import mdx from './InputTwo.mdx';

export default {
component: InputTwo,
title: 'Components / InputTwo',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { LabelStack } from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './LabelStack.mdx';

export default {
component: LabelStack,
title: 'Components / LabelStack',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Meter } from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './Meter.mdx';

export default {
component: Meter,
title: 'Components / Meter',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Canvas, Story, ArgsTable } from "@storybook/addon-docs/blocks";
import { MiddleEllipsis } from "@proton/components";

# Middle Ellipsis
# MiddleEllipsis

When you don't have enough space to display something, but you want to display the end of this content. For sure, if you have enough room, ellipsis won't appear. :)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { MiddleEllipsis } from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './MiddleEllipsis.mdx';

export default {
component: MiddleEllipsis,
title: 'Components / Middle Ellipsis',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Button, CreateNotificationOptions, useNotifications } from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './Notification.mdx';

export default {
component: Notification,
title: 'Components / Notification',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Price } from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './Price.mdx';

export default {
component: Price,
title: 'Components / Price',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useState, useEffect } from 'react';
import { Progress } from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './Progress.mdx';

export default {
component: Progress,
title: 'Components / Progress',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useState } from 'react';
import { Scale } from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './Scale.mdx';

export default {
component: Scale,
title: 'Components / Scale',
title: getTitle(__filename, false),
parameters: {
docs: {
page: mdx,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useRef, useState } from 'react';
import { SelectTwo, Option, Icon } from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './Select.mdx';

export default {
title: 'Components / Select',
title: getTitle(__filename, false),
component: SelectTwo,
parameters: {
docs: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { useState } from 'react';
import { Tabs } from '@proton/components';
import { getTitle } from '../../helpers/title';

import mdx from './Tabs.mdx';
import bulbasaur from '../../assets/bulbasaur.png';
import charmander from '../../assets/charmander.png';
import squirtle from '../../assets/squirtle.png';

import mdx from './Tabs.mdx';

export default {
title: 'Components / Tabs',
title: getTitle(__filename, false),
component: Tabs,
parameters: {
docs: {
Expand Down
Loading

0 comments on commit da04754

Please sign in to comment.