Skip to content

Commit

Permalink
Merge pull request #12583 from cesarsl/12534-title-space-insertion
Browse files Browse the repository at this point in the history
UI: Fix page title for non-alpha chars
  • Loading branch information
shilman committed Sep 28, 2020
2 parents 5aa08ce + 2730329 commit f300975
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 2 additions & 0 deletions examples/official-storybook/stories/core/unicode.stories.js
Expand Up @@ -5,3 +5,5 @@ storiesOf('Core/Unicode', module)
.add('😀', () => <p>❤️</p>)
.add('Кнопки', () => <p>нормальный</p>)
.add('바보', () => <p>🤷🏻‍♂️</p>);

storiesOf('Core/Unicode/Primário', module).add('😀', () => <p>❤️</p>);
9 changes: 2 additions & 7 deletions lib/ui/src/containers/preview.tsx
Expand Up @@ -7,12 +7,7 @@ import { Preview } from '../components/preview/preview';

export type Item = StoriesHash[keyof StoriesHash];

const nonAlphanumSpace = /[^a-z0-9 ]/gi;
const doubleSpace = /\s\s/gi;
const replacer = (match: string) => ` ${match} `;

const addExtraWhiteSpace = (input: string) =>
input.replace(nonAlphanumSpace, replacer).replace(doubleSpace, ' ');
const splitTitleAddExtraSpace = (input: string) => input.split('/').join(' / ').replace(/\s\s/, ' ');

const getDescription = (item: Item) => {
if (isRoot(item)) {
Expand All @@ -23,7 +18,7 @@ const getDescription = (item: Item) => {
}
if (isStory(item)) {
const { kind, name } = item;
return kind && name ? addExtraWhiteSpace(`${kind} - ${name} ⋅ Storybook`) : 'Storybook';
return kind && name ? splitTitleAddExtraSpace(`${kind} - ${name} ⋅ Storybook`) : 'Storybook';
}

return 'Storybook';
Expand Down

0 comments on commit f300975

Please sign in to comment.