Skip to content

Commit

Permalink
Merge branch 'nephila-feature/show-value-option'
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Siekmann committed Oct 28, 2021
2 parents 8a8c106 + 8ce11fc commit 0d3a021
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ import { DesignTokenDocBlock } from 'storybook-design-token/dist/doc-blocks';
<DesignTokenDocBlock categoryName="Colors" viewType="card" />;
```

The `categoryName` parameter references your token category name (the part after `@tokens` in your stylesheet annotations). The `viewType` parameter can be set to `card` or `table` to switch between both presentations.
The `categoryName` parameter references your token category name (the part after `@tokens` in your stylesheet annotations). The `viewType` parameter can be set to `card` or `table` to switch between both presentations. In some cases you might want to hide the token values. You can do that by passing `showValueColumn={false}`.
Check the [demo file](https://github.com/UX-and-I/storybook-design-token/blob/v1/demo/src/design-tokens/colors.stories.mdx) for usage examples.

## Browser support
Expand Down
14 changes: 12 additions & 2 deletions addon/src/components/DesignTokenDocBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { TokenTable } from './TokenTable';

export interface DesignTokenDocBlockProps {
categoryName: string;
showValueColumn?: boolean;
viewType?: 'card' | 'table';
}

Expand All @@ -28,6 +29,7 @@ function getMainStory(context: CompatDocsContextProps) {

export const DesignTokenDocBlock = ({
categoryName,
showValueColumn = true,
viewType = 'table'
}: DesignTokenDocBlockProps) => {
const context = useContext(DocsContext);
Expand Down Expand Up @@ -66,11 +68,19 @@ export const DesignTokenDocBlock = ({
<Container className="design-token-container">
{viewType === 'table' && (
<Card className="design-token-card">
<TokenTable categories={tab.categories} readonly />
<TokenTable
categories={tab.categories}
readonly
showValueColumn={showValueColumn}
/>
</Card>
)}
{viewType === 'card' && (
<TokenCards categories={tab.categories} readonly />
<TokenCards
categories={tab.categories}
readonly
showValueColumn={showValueColumn}
/>
)}
</Container>
);
Expand Down
30 changes: 19 additions & 11 deletions addon/src/components/TokenCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ import { ToolButton } from './ToolButton';
interface TokenCardsProps {
categories: Category[];
readonly?: boolean;
showValueColumn?: boolean;
}

export const TokenCards = ({ categories, readonly }: TokenCardsProps) => {
export const TokenCards = ({
categories,
readonly,
showValueColumn = true
}: TokenCardsProps) => {
const [tokenValueOverwrites, setTokenValueOverwrites] = useState<{
[tokenName: string]: any;
}>({});
Expand Down Expand Up @@ -86,16 +91,19 @@ export const TokenCards = ({ categories, readonly }: TokenCardsProps) => {
</WithTooltip>
)}

<TokenValue
onValueChange={(newValue) => {
setTokenValueOverwrites((tokenValueOverwrites) => ({
...tokenValueOverwrites,
[token.name]: newValue === token.rawValue ? undefined : newValue
}));
}}
readonly={readonly}
token={token}
/>
{showValueColumn && (
<TokenValue
onValueChange={(newValue) => {
setTokenValueOverwrites((tokenValueOverwrites) => ({
...tokenValueOverwrites,
[token.name]:
newValue === token.rawValue ? undefined : newValue
}));
}}
readonly={readonly}
token={token}
/>
)}

<TokenPreview
token={{
Expand Down
37 changes: 22 additions & 15 deletions addon/src/components/TokenTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ import { ToolButton } from './ToolButton';
interface TokenTableProps {
categories: Category[];
readonly?: boolean;
showValueColumn?: boolean;
}

export const TokenTable = ({ categories, readonly }: TokenTableProps) => {
export const TokenTable = ({
categories,
readonly,
showValueColumn = true
}: TokenTableProps) => {
const [tokenValueOverwrites, setTokenValueOverwrites] = useState<{
[tokenName: string]: any;
}>({});
Expand Down Expand Up @@ -111,7 +116,7 @@ export const TokenTable = ({ categories, readonly }: TokenTableProps) => {
<thead className="docblock-argstable-head">
<tr>
<th>Name</th>
<th>Value</th>
{showValueColumn && <th>Value</th>}
<th>Preview</th>
</tr>
</thead>
Expand Down Expand Up @@ -145,19 +150,21 @@ export const TokenTable = ({ categories, readonly }: TokenTableProps) => {
</WithTooltip>
)}
</td>
<td>
<TokenValue
onValueChange={(newValue) => {
setTokenValueOverwrites((tokenValueOverwrites) => ({
...tokenValueOverwrites,
[token.name]:
newValue === token.rawValue ? undefined : newValue
}));
}}
readonly={readonly}
token={token}
/>
</td>
{showValueColumn && (
<td>
<TokenValue
onValueChange={(newValue) => {
setTokenValueOverwrites((tokenValueOverwrites) => ({
...tokenValueOverwrites,
[token.name]:
newValue === token.rawValue ? undefined : newValue
}));
}}
readonly={readonly}
token={token}
/>
</td>
)}
<td>
<TokenPreview
token={{
Expand Down

0 comments on commit 0d3a021

Please sign in to comment.