2022-08-18 19:51:53 +02:00
|
|
|
import React from 'react';
|
2023-06-05 17:55:20 +02:00
|
|
|
import { StoryFn, Meta } from '@storybook/react';
|
2022-08-18 19:51:53 +02:00
|
|
|
import {
|
2023-06-05 17:55:20 +02:00
|
|
|
Display,
|
2023-02-02 21:15:26 +01:00
|
|
|
BackgroundColor,
|
|
|
|
BorderColor,
|
2023-04-28 01:28:39 +02:00
|
|
|
FontWeight,
|
|
|
|
FontStyle,
|
2023-02-02 21:15:26 +01:00
|
|
|
TextColor,
|
2023-04-28 01:28:39 +02:00
|
|
|
TextAlign,
|
|
|
|
OverflowWrap,
|
|
|
|
TextTransform,
|
2023-06-05 17:55:20 +02:00
|
|
|
BlockSize,
|
|
|
|
FlexDirection,
|
2023-02-02 21:15:26 +01:00
|
|
|
TextVariant,
|
|
|
|
Color,
|
2022-08-18 19:51:53 +02:00
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
|
|
|
|
import Box from '../../ui/box';
|
|
|
|
import README from './README.mdx';
|
2023-04-03 19:42:37 +02:00
|
|
|
import { Text } from './text';
|
|
|
|
import { ValidTag, TextDirection } from './text.types';
|
2022-08-18 19:51:53 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
title: 'Components/ComponentLibrary/Text',
|
2023-04-03 19:42:37 +02:00
|
|
|
component: Text,
|
2023-01-20 20:27:46 +01:00
|
|
|
|
2022-08-18 19:51:53 +02:00
|
|
|
parameters: {
|
|
|
|
docs: {
|
|
|
|
page: README,
|
|
|
|
},
|
|
|
|
},
|
2023-06-05 17:55:20 +02:00
|
|
|
} as Meta<typeof Text>;
|
2022-08-18 19:51:53 +02:00
|
|
|
|
|
|
|
function renderBackgroundColor(color) {
|
|
|
|
let bgColor;
|
|
|
|
switch (color) {
|
2023-02-02 21:15:26 +01:00
|
|
|
case Color.overlayInverse:
|
|
|
|
bgColor = BackgroundColor.overlayDefault;
|
2022-08-18 19:51:53 +02:00
|
|
|
break;
|
2023-02-02 21:15:26 +01:00
|
|
|
case Color.primaryInverse:
|
|
|
|
bgColor = BackgroundColor.primaryDefault;
|
2022-08-18 19:51:53 +02:00
|
|
|
break;
|
2023-02-02 21:15:26 +01:00
|
|
|
case Color.errorInverse:
|
|
|
|
bgColor = BackgroundColor.errorDefault;
|
2022-08-18 19:51:53 +02:00
|
|
|
break;
|
2023-02-02 21:15:26 +01:00
|
|
|
case Color.warningInverse:
|
|
|
|
bgColor = BackgroundColor.warningDefault;
|
2022-08-18 19:51:53 +02:00
|
|
|
break;
|
2023-02-02 21:15:26 +01:00
|
|
|
case Color.successInverse:
|
|
|
|
bgColor = BackgroundColor.successDefault;
|
2022-08-18 19:51:53 +02:00
|
|
|
break;
|
2023-02-02 21:15:26 +01:00
|
|
|
case Color.infoInverse:
|
|
|
|
bgColor = BackgroundColor.infoDefault;
|
2022-08-18 19:51:53 +02:00
|
|
|
break;
|
2023-03-23 21:00:37 +01:00
|
|
|
case Color.goerliInverse:
|
|
|
|
bgColor = BackgroundColor.goerli;
|
|
|
|
break;
|
|
|
|
case Color.sepoliaInverse:
|
|
|
|
bgColor = BackgroundColor.sepolia;
|
|
|
|
break;
|
2023-06-15 13:38:07 +02:00
|
|
|
case Color.lineaGoerliInverse:
|
|
|
|
bgColor = BackgroundColor.lineaGoerli;
|
2023-03-23 21:00:37 +01:00
|
|
|
break;
|
2023-06-16 18:35:33 +02:00
|
|
|
case Color.lineaMainnetInverse:
|
|
|
|
bgColor = BackgroundColor.lineaMainnet;
|
|
|
|
break;
|
2022-08-18 19:51:53 +02:00
|
|
|
default:
|
|
|
|
bgColor = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bgColor;
|
|
|
|
}
|
|
|
|
|
2023-06-05 17:55:20 +02:00
|
|
|
const Template: StoryFn<typeof Text> = (args) => (
|
2023-04-03 19:42:37 +02:00
|
|
|
<Text {...args}>{args.children}</Text>
|
|
|
|
);
|
2022-08-18 19:51:53 +02:00
|
|
|
|
2023-04-03 19:42:37 +02:00
|
|
|
export const DefaultStory = Template.bind({});
|
2022-08-18 19:51:53 +02:00
|
|
|
|
|
|
|
DefaultStory.args = {
|
|
|
|
children: 'The quick orange fox jumped over the lazy dog.',
|
|
|
|
};
|
|
|
|
|
2023-04-03 19:42:37 +02:00
|
|
|
DefaultStory.storyName = 'Default';
|
|
|
|
|
2022-08-18 19:51:53 +02:00
|
|
|
export const Variant = (args) => (
|
|
|
|
<>
|
2023-02-02 21:15:26 +01:00
|
|
|
{Object.values(TextVariant).map((variant) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<Text {...args} variant={variant} key={variant}>
|
|
|
|
{args.children || variant}
|
|
|
|
</Text>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
2023-06-05 17:55:20 +02:00
|
|
|
export const ColorStory: StoryFn<typeof Text> = (args) => {
|
2023-02-02 21:15:26 +01:00
|
|
|
// Index of last valid color in TextColor array
|
2022-08-18 19:51:53 +02:00
|
|
|
return (
|
|
|
|
<>
|
2023-02-02 21:15:26 +01:00
|
|
|
{Object.values(TextColor).map((color) => {
|
2022-08-18 19:51:53 +02:00
|
|
|
return (
|
|
|
|
<Text
|
|
|
|
{...args}
|
|
|
|
backgroundColor={renderBackgroundColor(color)}
|
|
|
|
color={color}
|
|
|
|
key={color}
|
|
|
|
>
|
|
|
|
{color}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2023-02-02 21:15:26 +01:00
|
|
|
ColorStory.storyName = 'Color';
|
2022-08-18 19:51:53 +02:00
|
|
|
|
2023-06-05 17:55:20 +02:00
|
|
|
export const FontWeightStory: StoryFn<typeof Text> = (args) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<>
|
2023-04-28 01:28:39 +02:00
|
|
|
{Object.values(FontWeight).map((weight) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<Text {...args} fontWeight={weight} key={weight}>
|
|
|
|
{weight}
|
|
|
|
</Text>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
2023-04-28 01:28:39 +02:00
|
|
|
FontWeightStory.storyName = 'Font Weight';
|
|
|
|
|
2023-06-05 17:55:20 +02:00
|
|
|
export const FontStyleStory: StoryFn<typeof Text> = (args) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<>
|
2023-04-28 01:28:39 +02:00
|
|
|
{Object.values(FontStyle).map((style) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<Text {...args} fontStyle={style} key={style}>
|
|
|
|
{style}
|
|
|
|
</Text>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
2023-04-28 01:28:39 +02:00
|
|
|
FontStyleStory.storyName = 'Font Style';
|
|
|
|
|
2023-06-05 17:55:20 +02:00
|
|
|
export const TextTransformStory: StoryFn<typeof Text> = (args) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<>
|
2023-04-28 01:28:39 +02:00
|
|
|
{Object.values(TextTransform).map((transform) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<Text {...args} textTransform={transform} key={transform}>
|
|
|
|
{transform}
|
|
|
|
</Text>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
2023-04-28 01:28:39 +02:00
|
|
|
TextTransformStory.storyName = 'Text Transform';
|
|
|
|
|
2023-06-05 17:55:20 +02:00
|
|
|
export const TextAlignStory: StoryFn<typeof Text> = (args) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<>
|
2023-04-28 01:28:39 +02:00
|
|
|
{Object.values(TextAlign).map((align) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<Text {...args} textAlign={align} key={align}>
|
|
|
|
{align}
|
|
|
|
</Text>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
2023-04-28 01:28:39 +02:00
|
|
|
TextAlignStory.storyName = 'Text Align';
|
|
|
|
|
2023-06-05 17:55:20 +02:00
|
|
|
export const OverflowWrapStory: StoryFn<typeof Text> = (args) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<Box
|
2023-02-02 21:15:26 +01:00
|
|
|
borderColor={BorderColor.warningDefault}
|
2023-06-05 17:55:20 +02:00
|
|
|
display={Display.Block}
|
2023-04-03 19:42:37 +02:00
|
|
|
style={{ width: 200 }}
|
2022-08-18 19:51:53 +02:00
|
|
|
>
|
2023-04-28 01:28:39 +02:00
|
|
|
<Text {...args} overflowWrap={OverflowWrap.Normal}>
|
|
|
|
{OverflowWrap.Normal}: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d
|
2022-08-18 19:51:53 +02:00
|
|
|
</Text>
|
2023-04-28 01:28:39 +02:00
|
|
|
<Text {...args} overflowWrap={OverflowWrap.BreakWord}>
|
|
|
|
{OverflowWrap.BreakWord}: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d
|
2022-08-18 19:51:53 +02:00
|
|
|
</Text>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
|
2023-04-28 01:28:39 +02:00
|
|
|
OverflowWrapStory.storyName = 'Overflow Wrap';
|
|
|
|
|
2023-06-05 17:55:20 +02:00
|
|
|
export const Ellipsis: StoryFn<typeof Text> = (args) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<Box
|
2023-02-02 21:15:26 +01:00
|
|
|
borderColor={BorderColor.primaryDefault}
|
2023-06-05 17:55:20 +02:00
|
|
|
display={Display.Block}
|
|
|
|
width={BlockSize.OneThird}
|
2022-08-18 19:51:53 +02:00
|
|
|
>
|
|
|
|
<Text {...args} ellipsis>
|
|
|
|
Ellipsis: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d
|
|
|
|
</Text>
|
|
|
|
<Text {...args}>
|
|
|
|
No Ellipsis: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d
|
|
|
|
</Text>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
|
2023-06-05 17:55:20 +02:00
|
|
|
export const As: StoryFn<typeof Text> = (args) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<>
|
2023-04-03 19:42:37 +02:00
|
|
|
{Object.keys(ValidTag).map((tag) => {
|
|
|
|
if (ValidTag[tag] === ValidTag.Input) {
|
|
|
|
return (
|
|
|
|
<Text
|
|
|
|
key={ValidTag[tag]}
|
|
|
|
{...args}
|
|
|
|
as={ValidTag[tag]}
|
|
|
|
placeholder={ValidTag[tag]}
|
|
|
|
/>
|
|
|
|
);
|
2022-10-19 20:09:38 +02:00
|
|
|
}
|
|
|
|
return (
|
2023-04-03 19:42:37 +02:00
|
|
|
<div key={ValidTag[tag]}>
|
|
|
|
<Text {...args} as={ValidTag[tag]}>
|
|
|
|
{ValidTag[tag]}
|
2022-10-19 20:09:38 +02:00
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
2022-08-18 19:51:53 +02:00
|
|
|
</>
|
|
|
|
);
|
2022-12-15 19:49:47 +01:00
|
|
|
|
2023-06-05 17:55:20 +02:00
|
|
|
export const TextDirectionStory: StoryFn<typeof Text> = (args) => (
|
2022-12-15 19:49:47 +01:00
|
|
|
<Box
|
|
|
|
style={{ maxWidth: 300 }}
|
2023-06-05 17:55:20 +02:00
|
|
|
display={Display.Flex}
|
|
|
|
flexDirection={FlexDirection.Column}
|
2022-12-15 19:49:47 +01:00
|
|
|
gap={4}
|
|
|
|
>
|
2023-04-03 19:42:37 +02:00
|
|
|
<Text {...args} textDirection={TextDirection.LeftToRight}>
|
2022-12-15 19:49:47 +01:00
|
|
|
This is left to right (ltr) for English and most languages
|
|
|
|
</Text>
|
2023-04-03 19:42:37 +02:00
|
|
|
<Text {...args} textDirection={TextDirection.RightToLeft}>
|
2022-12-15 19:49:47 +01:00
|
|
|
This is right to left (rtl) for use with other laguanges such as Arabic.
|
|
|
|
This Enlgish example is incorrect usage.
|
|
|
|
</Text>
|
2023-04-03 19:42:37 +02:00
|
|
|
<Text {...args} textDirection={TextDirection.Auto}>
|
2022-12-15 19:49:47 +01:00
|
|
|
Let the user agent decide with the auto option
|
|
|
|
</Text>
|
|
|
|
</Box>
|
|
|
|
);
|
2023-04-26 21:46:03 +02:00
|
|
|
|
2023-06-05 17:55:20 +02:00
|
|
|
export const Strong: StoryFn<typeof Text> = (args) => (
|
2023-04-26 21:46:03 +02:00
|
|
|
<>
|
|
|
|
<Text {...args} as="strong">
|
|
|
|
This is an as="strong" demo.
|
|
|
|
</Text>
|
|
|
|
<Text {...args}>
|
|
|
|
This is a <strong>strong element</strong> demo.
|
|
|
|
</Text>
|
|
|
|
</>
|
|
|
|
);
|