2022-08-18 19:51:53 +02:00
|
|
|
import React from 'react';
|
2023-04-03 19:42:37 +02:00
|
|
|
import { ComponentStory, ComponentMeta } from '@storybook/react';
|
2022-08-18 19:51:53 +02:00
|
|
|
import {
|
|
|
|
DISPLAY,
|
2023-02-02 21:15:26 +01:00
|
|
|
BackgroundColor,
|
|
|
|
BorderColor,
|
2022-08-18 19:51:53 +02:00
|
|
|
FONT_WEIGHT,
|
|
|
|
FONT_STYLE,
|
2023-02-02 21:15:26 +01:00
|
|
|
TextColor,
|
2022-08-18 19:51:53 +02:00
|
|
|
TEXT_ALIGN,
|
|
|
|
OVERFLOW_WRAP,
|
|
|
|
TEXT_TRANSFORM,
|
|
|
|
FRACTIONS,
|
2022-12-15 19:49:47 +01:00
|
|
|
FLEX_DIRECTION,
|
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-04-03 19:42:37 +02:00
|
|
|
} as ComponentMeta<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;
|
|
|
|
case Color.lineaTestnetInverse:
|
|
|
|
bgColor = BackgroundColor.lineaTestnet;
|
|
|
|
break;
|
2022-08-18 19:51:53 +02:00
|
|
|
default:
|
|
|
|
bgColor = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bgColor;
|
|
|
|
}
|
|
|
|
|
2023-04-03 19:42:37 +02:00
|
|
|
const Template: ComponentStory<typeof Text> = (args) => (
|
|
|
|
<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-04-03 19:42:37 +02:00
|
|
|
export const ColorStory: ComponentStory<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-04-03 19:42:37 +02:00
|
|
|
export const FontWeight: ComponentStory<typeof Text> = (args) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<>
|
|
|
|
{Object.values(FONT_WEIGHT).map((weight) => (
|
|
|
|
<Text {...args} fontWeight={weight} key={weight}>
|
|
|
|
{weight}
|
|
|
|
</Text>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
2023-04-03 19:42:37 +02:00
|
|
|
export const FontStyle: ComponentStory<typeof Text> = (args) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<>
|
|
|
|
{Object.values(FONT_STYLE).map((style) => (
|
|
|
|
<Text {...args} fontStyle={style} key={style}>
|
|
|
|
{style}
|
|
|
|
</Text>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
2023-04-03 19:42:37 +02:00
|
|
|
export const TextTransform: ComponentStory<typeof Text> = (args) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<>
|
|
|
|
{Object.values(TEXT_TRANSFORM).map((transform) => (
|
|
|
|
<Text {...args} textTransform={transform} key={transform}>
|
|
|
|
{transform}
|
|
|
|
</Text>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
2023-04-03 19:42:37 +02:00
|
|
|
export const TextAlign: ComponentStory<typeof Text> = (args) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<>
|
|
|
|
{Object.values(TEXT_ALIGN).map((align) => (
|
|
|
|
<Text {...args} textAlign={align} key={align}>
|
|
|
|
{align}
|
|
|
|
</Text>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
2023-04-03 19:42:37 +02:00
|
|
|
export const OverflowWrap: ComponentStory<typeof Text> = (args) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<Box
|
2023-02-02 21:15:26 +01:00
|
|
|
borderColor={BorderColor.warningDefault}
|
2022-08-18 19:51:53 +02:00
|
|
|
display={DISPLAY.BLOCK}
|
2023-04-03 19:42:37 +02:00
|
|
|
style={{ width: 200 }}
|
2022-08-18 19:51:53 +02:00
|
|
|
>
|
|
|
|
<Text {...args} overflowWrap={OVERFLOW_WRAP.NORMAL}>
|
|
|
|
{OVERFLOW_WRAP.NORMAL}: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d
|
|
|
|
</Text>
|
|
|
|
<Text {...args} overflowWrap={OVERFLOW_WRAP.BREAK_WORD}>
|
|
|
|
{OVERFLOW_WRAP.BREAK_WORD}: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d
|
|
|
|
</Text>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
|
2023-04-03 19:42:37 +02:00
|
|
|
export const Ellipsis: ComponentStory<typeof Text> = (args) => (
|
2022-08-18 19:51:53 +02:00
|
|
|
<Box
|
2023-02-02 21:15:26 +01:00
|
|
|
borderColor={BorderColor.primaryDefault}
|
2022-08-18 19:51:53 +02:00
|
|
|
display={DISPLAY.BLOCK}
|
|
|
|
width={FRACTIONS.ONE_THIRD}
|
|
|
|
>
|
|
|
|
<Text {...args} ellipsis>
|
|
|
|
Ellipsis: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d
|
|
|
|
</Text>
|
|
|
|
<Text {...args}>
|
|
|
|
No Ellipsis: 0x39013f961c378f02c2b82a6e1d31e9812786fd9d
|
|
|
|
</Text>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
|
2023-04-03 19:42:37 +02:00
|
|
|
export const As: ComponentStory<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-04-03 19:42:37 +02:00
|
|
|
export const TextDirectionStory: ComponentStory<typeof Text> = (args) => (
|
2022-12-15 19:49:47 +01:00
|
|
|
<Box
|
|
|
|
style={{ maxWidth: 300 }}
|
|
|
|
display={DISPLAY.FLEX}
|
|
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
|
|
|
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>
|
|
|
|
);
|