-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[explorer] Base UI Components (#4572)
* Integrate storybook * Remove some stories * Fixing storybook * Introduce base UI components * Fix line-heights * format * Fix lint error * Rename heading variant and simplify leading * Rename tag to as * Remove CSS reset for now * comment * re-install * lint fix
- Loading branch information
1 parent
ee5a7d5
commit 01a752a
Showing
13 changed files
with
8,144 additions
and
1,641 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
strict-peer-dependencies=false | ||
public-hoist-pattern[]=*storybook* |
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
# production | ||
/build | ||
/storybook-static | ||
|
||
# misc | ||
.env.local | ||
|
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,18 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
module.exports = { | ||
stories: [ | ||
'../src/**/*.stories.mdx', | ||
'../src/**/*.stories.@(js|jsx|ts|tsx)', | ||
], | ||
addons: ['@storybook/addon-a11y', '@storybook/addon-essentials'], | ||
framework: '@storybook/react', | ||
core: { | ||
builder: '@storybook/builder-vite', | ||
}, | ||
features: { | ||
storyStoreV7: true, | ||
}, | ||
staticDirs: ['../public'], | ||
}; |
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,3 @@ | ||
<script> | ||
window.global = window; | ||
</script> |
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,14 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import '../src/index.css'; | ||
|
||
export const parameters = { | ||
actions: { argTypesRegex: '^on[A-Z].*' }, | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/, | ||
}, | ||
}, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { cva, type VariantProps } from 'class-variance-authority'; | ||
import { type ReactNode } from 'react'; | ||
|
||
const headingStyles = cva( | ||
[ | ||
'font-sans', | ||
// TODO: Remove when CSS reset is applied. | ||
'my-0', | ||
], | ||
{ | ||
variants: { | ||
variant: { | ||
heading1: 'text-h1', | ||
heading2: 'text-h2', | ||
heading3: 'text-h3', | ||
heading4: 'text-h4', | ||
heading5: 'text-h5', | ||
heading6: 'text-h6', | ||
}, | ||
weight: { | ||
medium: 'font-medium', | ||
semibold: 'font-semibold', | ||
bold: 'font-bold', | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: 'heading1', | ||
weight: 'semibold', | ||
}, | ||
} | ||
); | ||
|
||
export interface HeadingProps extends VariantProps<typeof headingStyles> { | ||
/** | ||
* The HTML element that will be rendered. | ||
* By default, we render a "div" in order to separate presentational styles from semantic markup. | ||
*/ | ||
as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'div'; | ||
children: ReactNode; | ||
} | ||
|
||
export function Heading({ | ||
as: Tag = 'div', | ||
children, | ||
...styleProps | ||
}: HeadingProps) { | ||
return <Tag className={headingStyles(styleProps)}>{children}</Tag>; | ||
} |
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,40 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { cva, type VariantProps } from 'class-variance-authority'; | ||
import { type ReactNode } from 'react'; | ||
|
||
const textStyles = cva(['font-sans'], { | ||
variants: { | ||
weight: { | ||
medium: 'font-medium', | ||
semibold: 'font-semibold', | ||
bold: 'font-bold', | ||
}, | ||
variant: { | ||
body: 'text-body', | ||
bodySmall: 'text-bodySmall', | ||
subtitle: 'text-subtitle', | ||
subtitleSmall: 'text-subtitleSmall', | ||
subtitleSmallExtra: 'text-subtitleSmallExtra', | ||
caption: 'uppercase text-caption', | ||
captionSmall: 'uppercase text-captionSmall ', | ||
}, | ||
italic: { | ||
true: 'italic', | ||
false: '', | ||
}, | ||
}, | ||
defaultVariants: { | ||
weight: 'medium', | ||
variant: 'body', | ||
}, | ||
}); | ||
|
||
export interface TextProps extends VariantProps<typeof textStyles> { | ||
children: ReactNode; | ||
} | ||
|
||
export function Text({ children, ...styleProps }: TextProps) { | ||
return <div className={textStyles(styleProps)}>{children}</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { type ComponentStory, type ComponentMeta } from '@storybook/react'; | ||
|
||
import { Heading } from '../Heading'; | ||
|
||
export default { | ||
title: 'UI/Heading', | ||
component: Heading, | ||
} as ComponentMeta<typeof Heading>; | ||
|
||
const Template: ComponentStory<typeof Heading> = (args) => ( | ||
<div> | ||
<Heading {...args} weight="bold"> | ||
This is a sample heading. | ||
</Heading> | ||
<Heading {...args} weight="semibold"> | ||
This is a sample heading. | ||
</Heading> | ||
<Heading {...args} weight="medium"> | ||
This is a sample heading. | ||
</Heading> | ||
</div> | ||
); | ||
|
||
export const Heading1 = Template.bind({}); | ||
Heading1.args = { as: 'h1', variant: 'heading1' }; | ||
|
||
export const Heading2 = Template.bind({}); | ||
Heading2.args = { as: 'h2', variant: 'heading2' }; | ||
|
||
export const Heading3 = Template.bind({}); | ||
Heading3.args = { as: 'h3', variant: 'heading3' }; | ||
|
||
export const Heading4 = Template.bind({}); | ||
Heading4.args = { as: 'h4', variant: 'heading4' }; | ||
|
||
export const Heading5 = Template.bind({}); | ||
Heading5.args = { as: 'h5', variant: 'heading5' }; | ||
|
||
export const Heading6 = Template.bind({}); | ||
Heading6.args = { as: 'h6', variant: 'heading6' }; |
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,53 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { type ComponentMeta, type Story } from '@storybook/react'; | ||
import { Fragment } from 'react'; | ||
|
||
import { Text, type TextProps } from '../Text'; | ||
|
||
export default { | ||
title: 'UI/Text', | ||
component: Text, | ||
} as ComponentMeta<typeof Text>; | ||
|
||
const Template: Story<{ | ||
variants: TextProps['variant'][]; | ||
weights?: TextProps['weight'][]; | ||
italic?: boolean; | ||
}> = ({ variants, weights = ['medium', 'semibold'], italic }) => ( | ||
<div> | ||
{variants.map((variant) => ( | ||
<Fragment key={variant}> | ||
{weights.map((weight) => ( | ||
<Text key={weight} variant={variant} weight={weight}> | ||
{variant} - {weight} | ||
</Text> | ||
))} | ||
|
||
{italic && ( | ||
<Text variant={variant} italic> | ||
{variant} - Italic | ||
</Text> | ||
)} | ||
</Fragment> | ||
))} | ||
</div> | ||
); | ||
|
||
export const Body = Template.bind({}); | ||
Body.args = { | ||
variants: ['body', 'bodySmall'], | ||
italic: true, | ||
}; | ||
|
||
export const Subtitle = Template.bind({}); | ||
Subtitle.args = { | ||
variants: ['subtitle', 'subtitleSmall', 'subtitleSmallExtra'], | ||
}; | ||
|
||
export const Caption = Template.bind({}); | ||
Caption.args = { | ||
variants: ['caption', 'captionSmall'], | ||
weights: ['medium', 'semibold', 'bold'], | ||
}; |
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.