forked from ljcl/storybook-addon-cssprops
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add customProperties & group parameter
- Loading branch information
Showing
12 changed files
with
105 additions
and
57 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
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
13 changes: 7 additions & 6 deletions
13
packages/storybook-addon-component-tokens/src/components/CssPropsPanel.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
14 changes: 14 additions & 0 deletions
14
packages/storybook-addon-component-tokens/src/constants.ts
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 |
---|---|---|
@@ -1,2 +1,16 @@ | ||
import { | ||
FullCustomPropertyValue, | ||
FullExtractResult, | ||
} from "custom-property-extract/dist/types"; | ||
|
||
export const PARAM_KEY = "cssprops" as const; | ||
export const ADDON_ID = "addon-component-tokens" as const; | ||
export type Group = (customProperty: FullCustomPropertyValue) => { | ||
label: string; | ||
category?: string; | ||
subcategory?: string; | ||
}; | ||
export type CssPropsParameter = { | ||
customProperties?: FullExtractResult; | ||
group?: Group; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import { useParameter } from "@storybook/api"; | ||
import { PARAM_KEY } from "./constants"; | ||
import { FullExtractResult } from "custom-property-extract/dist/types"; | ||
import { CssPropsParameter, PARAM_KEY } from "./constants"; | ||
|
||
export function getTitle(): string { | ||
const cssprops = useParameter<FullExtractResult>(PARAM_KEY, {}); | ||
const controlsCount = Object.values(cssprops).filter( | ||
(cssprop) => cssprop.length, | ||
).length; | ||
const { customProperties = {} } = useParameter<CssPropsParameter>(PARAM_KEY, { | ||
customProperties: {}, | ||
}); | ||
const controlsCount = Object.values(customProperties).flat().length; | ||
const suffix = controlsCount === 0 ? "" : ` (${controlsCount})`; | ||
return `Component Tokens${suffix}`; | ||
} |