-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Implement StyleBlock component for components-specific customi…
…sations (#374)
- Loading branch information
Showing
20 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Controls, Description, Primary, Stories, Subtitle, Title } from '@storybook/blocks'; | ||
import { StyleBlock } from '../styleBlock'; | ||
|
||
export const DocsPage: React.FC = () => { | ||
return ( | ||
<> | ||
<Title /> | ||
<Subtitle /> | ||
<Description /> | ||
<Primary /> | ||
<Controls /> | ||
<Stories /> | ||
<StyleBlock /> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { DocsPage } from './docsPage'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './docsPage'; | ||
export * from './styleBlock'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { StyleBlock, type ICustomisationDoc } from './styleBlock'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Subheading, useOf } from '@storybook/blocks'; | ||
|
||
export interface ICustomisationDoc { | ||
/** | ||
* Name of the variable. | ||
*/ | ||
name: string; | ||
/** | ||
* Description of the variable. | ||
*/ | ||
description?: string; | ||
/** | ||
* Default value of the variable. | ||
*/ | ||
value: string; | ||
} | ||
|
||
const parseCustomisations = (source = ''): ICustomisationDoc[] => { | ||
const customisationRegex = /(?:\/\*\s*(.*?)\s*\*\/\s+)?--([\w-]+):\s*(.*?);/g; | ||
const matches = Array.from(source.matchAll(customisationRegex)); | ||
|
||
const customisations = matches.map(([, description, name, value]) => ({ | ||
name: `--${name}`, | ||
description: description.trim(), | ||
value, | ||
})); | ||
|
||
return customisations; | ||
}; | ||
|
||
export const StyleBlock: React.FC = () => { | ||
const metaInfo = useOf<'meta'>('meta'); | ||
|
||
const source = metaInfo.preparedMeta.parameters.style as string | undefined; | ||
const customisations = parseCustomisations(source); | ||
|
||
if (!customisations.length) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col"> | ||
<Subheading>Customisations</Subheading> | ||
<table> | ||
<thead> | ||
<tr> | ||
<td>Name</td> | ||
<td>Description</td> | ||
<td>Default</td> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{customisations.map(({ name, value, description }) => ( | ||
<tr key={name}> | ||
<td>{name}</td> | ||
<td>{description}</td> | ||
<td>{value}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/core/components/dropdown/dropdownContainer/dropdownContainer.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/core/components/illustrations/illustrationHuman/illustrationHuman.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/core/components/illustrations/illustrationObject/illustrationObject.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters