Skip to content

Commit

Permalink
feat: preformatted text (#575)
Browse files Browse the repository at this point in the history
Closes 536
  • Loading branch information
JadhavJeet authored Nov 23, 2023
1 parent fafe140 commit 5d96a25
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/design-system/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
@import './code-snippet.css';
@import './abbreviate.css';
@import './keyboard-input.css';

@import './preformattedText.css';
7 changes: 7 additions & 0 deletions src/design-system/preformattedText.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.dcx-pre {
color: token('color-text-pre_body');
background-color: token('color-background-pre_box');
font-size: token('font-size-pre_body');
font-family: token('font-family-pre_body');
font-weight: token('font-weight-pre_body');
}
2 changes: 1 addition & 1 deletion src/design-system/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"font-size-formcontrol_label": "16px",
"font-size-highlight_body": "12px",
"font-size-paragraph": "12px",
"font-size-pre_body": "12px",
"font-size-pre_body": "16px",
"font-weight-body": "normal",
"font-weight-formcontrol_label": "normal",
"font-weight-highlight_body": "normal",
Expand Down
53 changes: 53 additions & 0 deletions stories/PreformattedText/design-system/AccessibleTheme.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { PreformattedText } from '../../../src/preformattedText/PreformattedText';
import style from '!raw-loader!../../themes/accessible.theme.css';
import { LiveProvider, LiveEditor } from 'react-live';
import { StorybookUtils } from '../../../core/storybook/StorybookUtils';

/**
* This a theme aimed at easing the vizualization of the different elements of the component in order to improve the experience for people that have visual impairments.
*/
export default {
title: 'DCXLibrary/Typography/PreformattedText/Design system/Accessible',
component: PreformattedText,
decorators: [
getStory => {
require('../../../dist/design-system/index.css');
require('../../themes/accessible.theme.css');
return getStory();
},
],
parameters: {
options: { showPanel: true },
actions: { disable: true },
},
tags: ['autodocs'],
};

export const ShowCase = {
parameters: {
backgrounds: {
default: 'dark',
values: [
{ name: 'dark', value: '#282c34' },
{ name: 'light', value: '#fff' },
],
},
},
render: () => (
<LiveProvider
code={StorybookUtils.getThemeCode('dcx-pre', style)}
disabled={true}
language="css"
>
<LiveEditor className="liveEditor" aria-label="editor" />
</LiveProvider>
),
};

export const Default = {
name: 'Default',
args: {
value: `Text in a pre element is displayed in a fixed-width font, and it preserves both spaces and
line breaks.`,
},
};
63 changes: 63 additions & 0 deletions stories/PreformattedText/design-system/DarkTheme.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { PreformattedText } from '../../../src/preformattedText/PreformattedText';
// eslint-disable-next-line import/no-webpack-loader-syntax
import style from '!raw-loader!../../themes/dark.theme.css';
import { LiveProvider, LiveEditor } from 'react-live';
import { StorybookUtils } from '../../../core/storybook/StorybookUtils';

/**
* This a theme showcases how to customize the component so it can be used on dark backgrounds.
*/
export default {
title: 'DCXLibrary/Typography/PreformattedText/Design system/Dark',
component: PreformattedText,
decorators: [
getStory => {
require('../../../dist/design-system/index.css');
require('../../themes/dark.theme.css');
return getStory();
},
],
parameters: {
options: { showPanel: true },
actions: { disable: true },
},
tags: ['autodocs'],
};

export const ShowCase = {
parameters: {
backgrounds: {
default: 'dark',
values: [
{ name: 'dark', value: '#282c34' },
{ name: 'light', value: '#fff' },
],
},
},
render: () => (
<LiveProvider
code={StorybookUtils.getThemeCode('dcx-pre', style)}
disabled={true}
language="css"
>
<LiveEditor className="liveEditor" aria-label="editor" />
</LiveProvider>
),
};

export const Default = {
name: 'Default',
parameters: {
backgrounds: {
default: 'dark',
values: [
{ name: 'dark', value: '#282c34' },
{ name: 'light', value: '#fff' },
],
},
},
args: {
value: `Text in a pre element is displayed in a fixed-width font, and it preserves both spaces and
line breaks.`,
},
};
27 changes: 27 additions & 0 deletions stories/PreformattedText/design-system/Default.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { PreformattedText } from '../../../src/preformattedText/PreformattedText';
/**
* Here we display the component in its natural preformattedText, importing only the base Design System styles.
*/
export default {
title: 'DCXLibrary/Typography/PreformattedText/Design system/Default',
component: PreformattedText,
decorators: [
getStory => {
require('../../../dist/design-system/index.css');
return getStory();
},
],
parameters: {
options: { showPanel: true },
actions: { disable: true },
},
tags: ['autodocs'],
};

export const Default = {
name: 'Default',
args: {
value: `Text in a pre element is displayed in a fixed-width font, and it preserves both spaces and
line breaks.`,
},
};
55 changes: 55 additions & 0 deletions stories/PreformattedText/design-system/MaterialTheme.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { PreformattedText } from '../../../src/preformattedText/PreformattedText';
import { LiveProvider, LiveEditor } from 'react-live';
// eslint-disable-next-line import/no-webpack-loader-syntax
import style from '!raw-loader!../../themes/material.theme.css';
import { StorybookUtils } from '../../../core/storybook/StorybookUtils';

/**
* This a theme showcases an appearance similar to Material UI can be achieved.
* If you copy paste this snippet inside your css file you'll get a material design style
*/
export default {
title: 'DCXLibrary/Typography/PreformattedText/Design system/Material',
component: PreformattedText,
decorators: [
getStory => {
require('../../../dist/design-system/index.css');
require('../../themes/material.theme.css');
return getStory();
},
],
parameters: {
options: { showPanel: true },
actions: { disable: true },
},
tags: ['autodocs'],
};

export const ShowCase = {
parameters: {
backgrounds: {
default: 'dark',
values: [
{ name: 'dark', value: '#282c34' },
{ name: 'light', value: '#fff' },
],
},
},
render: () => (
<LiveProvider
code={StorybookUtils.getThemeCode('dcx-pre', style)}
disabled={true}
language="css"
>
<LiveEditor className="liveEditor" aria-label="editor" />
</LiveProvider>
),
};

export const Default = {
name: 'Default',
args: {
value: `Text in a pre element is displayed in a fixed-width font, and it preserves both spaces and
line breaks.`,
},
};
24 changes: 24 additions & 0 deletions stories/PreformattedText/design-system/Playground.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable import/no-webpack-loader-syntax */
import style from '!raw-loader!../../../dist/design-system/preformattedText.css';
import TokensDecorator from '../../../core/storybook/TokensDecorator';
import { PreformattedText } from '../../../src/preformattedText/PreformattedText';

export default {
title: 'DCXLibrary/Typography/PreformattedText/Design system',
component: PreformattedText,
decorators: [
getStory => <TokensDecorator style={style}>{getStory()}</TokensDecorator>,
],
parameters: {
options: { showPanel: true },
actions: { disable: true },
},
};

export const Playground = {
name: 'Playground',
args: {
value: `Text in a pre element is displayed in a fixed-width font, and it preserves both spaces and
line breaks.`,
},
};
5 changes: 5 additions & 0 deletions stories/themes/dark.theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
--dcx-color-text-body: white;
}

.dcx-pre {
--dcx-color-text-pre_body: white;
--dcx-color-background-pre_box: transparent;
}

.dcx-insert-text {
--dcx-color-text-body: white;
}
Expand Down
5 changes: 4 additions & 1 deletion stories/themes/material.theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
--dcx-color-marker: rgba(0, 0, 0, 0.6);
}

.dcx-pre {
--dcx-color-text-pre_body: rgba(0, 0, 0, 0.6);
}

.dcx-abbreviate {
--dcx-border-radius-abbreviate: 8px;
}
}

0 comments on commit 5d96a25

Please # to comment.