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.
Breaking Change: Storybook 7 is required
- Loading branch information
Showing
22 changed files
with
5,648 additions
and
8,520 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v14.11.0 | ||
18.12 |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"sourceType": "unambiguous", | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"chrome": 100 | ||
} | ||
} | ||
], | ||
"@babel/preset-typescript", | ||
"@babel/preset-react" | ||
], | ||
"plugins": [] | ||
} |
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,11 +1,27 @@ | ||
import { dirname, join } from "path"; | ||
module.exports = { | ||
stories: [ | ||
"../stories/**/*.stories.mdx", | ||
"../stories/**/*.stories.{js,jsx,ts,tsx}", | ||
], | ||
addons: [ | ||
"@kickstartds/storybook-addon-component-tokens", | ||
"@storybook/addon-docs", | ||
"@storybook/addon-controls", | ||
getAbsolutePath("@kickstartds/storybook-addon-component-tokens"), | ||
getAbsolutePath("@storybook/addon-docs"), | ||
getAbsolutePath("@storybook/addon-controls"), | ||
], | ||
framework: { | ||
name: getAbsolutePath("@storybook/react-webpack5"), | ||
options: {}, | ||
}, | ||
docs: { | ||
autodocs: true, | ||
}, | ||
}; | ||
|
||
/** | ||
* This function is used to resolve the absolute path of a package. | ||
* It is needed in projects that use Yarn PnP or are set up within a monorepo. | ||
*/ | ||
function getAbsolutePath(value) { | ||
return dirname(require.resolve(join(value, "package.json"))); | ||
} |
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
32 changes: 22 additions & 10 deletions
32
packages/storybook-addon-component-tokens/src/components/CssPropsBlock.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,36 @@ | ||
import * as React from "react"; | ||
import { FC } from "react"; | ||
import { useOf, Of } from "@storybook/addon-docs"; | ||
import { FullExtractResult } from "custom-property-extract/dist/types"; | ||
import { CssPropsTable } from "./CssPropsTable"; | ||
import { DocsContext, DocsContextProps } from "@storybook/addon-docs"; | ||
import { hasEntries } from "./utils"; | ||
|
||
interface CssPropsBlockProps { | ||
customProperties: FullExtractResult; | ||
of?: Of; | ||
customProperties?: FullExtractResult; | ||
} | ||
|
||
/** | ||
* For use inside Storybook Docs and MDX | ||
*/ | ||
export const CssPropsBlock: React.FC<CssPropsBlockProps> = (props) => { | ||
const overrideCustomProperties = props.customProperties; | ||
export const CssPropsBlock: FC<CssPropsBlockProps> = (props) => { | ||
let cssprops: FullExtractResult = {}; | ||
|
||
const context = React.useContext<DocsContextProps>(DocsContext); | ||
const cssprops: FullExtractResult = { ...context?.parameters?.cssprops }; | ||
const customProperties = overrideCustomProperties || cssprops; | ||
try { | ||
const resolvedOf = useOf(props.of || "meta"); | ||
const { parameters = {} } = | ||
resolvedOf.type === "meta" | ||
? resolvedOf.csfFile.meta | ||
: resolvedOf.type === "story" | ||
? resolvedOf.story | ||
: resolvedOf.type === "component" | ||
? resolvedOf.projectAnnotations | ||
: {}; | ||
cssprops = { ...parameters.cssprops }; | ||
} catch (error) {} | ||
|
||
return hasEntries(customProperties) ? ( | ||
<CssPropsTable customProperties={customProperties} inAddonPanel={false} /> | ||
cssprops = props.customProperties || cssprops; | ||
|
||
return hasEntries(cssprops) ? ( | ||
<CssPropsTable customProperties={cssprops} inAddonPanel={false} /> | ||
) : null; | ||
}; |
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
Oops, something went wrong.