Skip to content

Commit

Permalink
docs: add superscript text example
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Jan 14, 2024
1 parent ba148a2 commit 7a03947
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/react-docs/pages/components/text/index.page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ You can format the `Text` component by passing `fontSize`, `lineHeight`, or othe

{render('./formatting-text')}

### Superscript text

{render('./superscript-text')}

### Text truncation

{render('./text-truncation')}
Expand Down
123 changes: 123 additions & 0 deletions packages/react-docs/pages/components/text/superscript-text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import {
Divider,
Flex,
Menu,
MenuDivider,
MenuItem,
MenuList,
Tab,
TabList,
Tabs,
Text,
useColorStyle,
} from '@tonic-ui/react';
import React from 'react';

const SuperscriptText = ({ sx, ...rest }) => {
const [colorStyle] = useColorStyle();
return (
<Text
as="sup"
sx={[
{
color: colorStyle.color.secondary,
display: 'inline-block',
fontSize: '.625rem',
fontStyle: 'italic',
fontWeight: 'normal',
lineHeight: 0,
position: 'relative',
top: '-0.6em',
verticalAlign: 'baseline',
},
...(Array.isArray(sx) ? sx : [sx]),
]}
{...rest}
/>
);
};

const Example1 = () => (
<Flex
alignItems="flex-start"
height={125}
>
<Menu isOpen>
<MenuList width="max-content">
<Text fontWeight="semibold" px="3x">
MENU GROUP
</Text>
<MenuDivider />
<MenuItem>
Menu Item
</MenuItem>
<MenuItem>
<Text mr="1x">Menu Item</Text>
<SuperscriptText>Preview</SuperscriptText>
</MenuItem>
</MenuList>
</Menu>
</Flex>
);

const Example2 = () => {
const [colorStyle] = useColorStyle();
return (
<Flex
backgroundColor={colorStyle.background.secondary}
height="12x"
alignItems="center"
px="4x"
>
<Flex alignItems="center">
<Text fontSize="xl" lineHeight="xl">
Product Name
</Text>
<sup>TM</sup>
</Flex>
<Divider
orientation="vertical"
height="5x"
mx="3x"
/>
<Flex alignItems="center">
<Text mr="1x">
App Name
</Text>
<SuperscriptText>Preview</SuperscriptText>
</Flex>
</Flex>
);
};

const Example3 = () => (
<Flex>
<Tabs>
<TabList>
<Tab>
<Text mr="1x">Tab Label</Text>
<SuperscriptText>Preview</SuperscriptText>
</Tab>
<Tab>
<Text mr="1x">Tab Label</Text>
<SuperscriptText>Preview</SuperscriptText>
</Tab>
<Tab>
<Text>Tab Label</Text>
</Tab>
</TabList>
</Tabs>
</Flex>
);

const App = () => (
<>
<Example1 />
<Divider my="4x" />
<Example2 />
<Divider my="4x" />
<Example3 />
</>
);

export default App;

0 comments on commit 7a03947

Please sign in to comment.