Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: small storybook and docs updates to SensitiveText component #28089

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions ui/components/component-library/sensitive-text/README.md
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to README.mdx

This file was deleted.

81 changes: 81 additions & 0 deletions ui/components/component-library/sensitive-text/README.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Controls, Canvas } from '@storybook/blocks';

import * as SensitiveTextStories from './sensitive-text.stories';

# SensitiveText

SensitiveText is a component that extends the Text component to handle sensitive information. It provides the ability to hide or show the text content, replacing it with dots when hidden.

<Canvas of={SensitiveTextStories.DefaultStory} />

## Props

The `SensitiveText` component extends the `Text` component. See the `Text` component for an extended list of props.

<Controls of={SensitiveTextStories.DefaultStory} />

### Children

The text content to be displayed or hidden.

<Canvas of={SensitiveTextStories.Children} />

```jsx
import { SensitiveText } from '../../component-library';

<SensitiveText>
Sensitive Information
</SensitiveText>
```


### IsHidden

Use the `isHidden` prop to determine whether the text should be hidden or visible. When `isHidden` is `true`, the component will display dots instead of the actual text.

<Canvas of={SensitiveTextStories.IsHidden} />

```jsx
import { SensitiveText } from '../../component-library';

<SensitiveText isHidden>
Sensitive Information
</SensitiveText>
```

### Length

Use the `length` prop to determine the length of the hidden text (number of dots). Can be a predefined `SensitiveTextLength` or a custom string number.

The following predefined length options are available:

- `SensitiveTextLength.Short`: `6`
- `SensitiveTextLength.Medium`: `9`
- `SensitiveTextLength.Long`: `12`
- `SensitiveTextLength.ExtraLong`: `20`

- The number of dots displayed is determined by the `length` prop.
- If an invalid `length` is provided, the component will fall back to `SensitiveTextLength.Short` and log a warning.
- Custom length values can be provided as strings, e.g. `15`.

<Canvas of={SensitiveTextStories.Length} />

```jsx
import { SensitiveText, SensitiveTextLength } from '../../component-library';

<SensitiveText length={SensitiveTextLength.Short}>
Length "short" (6 characters)
</SensitiveText>
<SensitiveText length={SensitiveTextLength.Medium}>
Length "medium" (9 characters)
</SensitiveText>
<SensitiveText length={SensitiveTextLength.Long}>
Length "long" (12 characters)
</SensitiveText>
<SensitiveText length={SensitiveTextLength.ExtraLong}>
Length "extra long" (20 characters)
</SensitiveText>
<SensitiveText length="15">
Length "15" (15 characters)
</SensitiveText>
```
Original file line number Diff line number Diff line change
@@ -1,39 +1,58 @@
import { StoryFn, Meta } from '@storybook/react';
import type { Meta, StoryObj } from '@storybook/react';
import React from 'react';
import { SensitiveText } from '.';
import { SensitiveTextLength } from './sensitive-text.types';
import README from './README.mdx';
import { Box } from '../box';
import {
Display,
FlexDirection,
} from '../../../helpers/constants/design-system';

export default {
const meta: Meta<typeof SensitiveText> = {
title: 'Components/ComponentLibrary/SensitiveText',
component: SensitiveText,
parameters: {
docs: {
page: README,
},
},
args: {
children: 'Sensitive information',
isHidden: false,
length: SensitiveTextLength.Short,
},
} as Meta<typeof SensitiveText>;

const Template: StoryFn<typeof SensitiveText> = (args) => {
return <SensitiveText {...args} />;
};
export default meta;
type Story = StoryObj<typeof SensitiveText>;

export const DefaultStory = Template.bind({});
export const DefaultStory: Story = {};
DefaultStory.storyName = 'Default';

export const HiddenText: StoryFn<typeof SensitiveText> = (args) => {
return <SensitiveText {...args} />;
export const Children: Story = {
args: {
children: 'Sensitive information',
},
render: (args) => (
<SensitiveText {...args} />
),
};
HiddenText.args = {
isHidden: true,

export const IsHidden: Story = {
args: {
isHidden: true,
},
render: (args) => (
<SensitiveText {...args} />
),
};

export const LengthVariants: StoryFn<typeof SensitiveText> = (args) => {
return (
export const Length: Story = {
args: {
isHidden: true,
},
render: (args) => (
<Box display={Display.Flex} flexDirection={FlexDirection.Column} gap={2}>
<SensitiveText {...args} length={SensitiveTextLength.Short}>
Length "short" (6 characters)
Expand All @@ -47,9 +66,9 @@ export const LengthVariants: StoryFn<typeof SensitiveText> = (args) => {
<SensitiveText {...args} length={SensitiveTextLength.ExtraLong}>
Length "extra long" (20 characters)
</SensitiveText>
<SensitiveText {...args} length="15">
Length "15" (15 characters)
</SensitiveText>
</Box>
);
};
LengthVariants.args = {
isHidden: true,
};
),
};