@bundle-stats/ui 4.16.0-beta.1 → 4.16.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/bundle-assets/bundle-assets.js +1 -1
- package/lib/components/bundle-assets/bundle-assets.js.map +1 -1
- package/lib/components/insights/insights.module.css +1 -0
- package/lib/components/metrics-table-export/metrics-table-export.js +3 -7
- package/lib/components/metrics-table-export/metrics-table-export.js.map +1 -1
- package/lib/components/preview-source/preview-source.js +8 -5
- package/lib/components/preview-source/preview-source.js.map +1 -1
- package/lib/components/preview-source/preview-source.module.css +12 -0
- package/lib/css/variables.css +4 -0
- package/lib/ui/dialog/dialog.module.css +3 -3
- package/lib/ui/index.js +3 -1
- package/lib/ui/index.js.map +1 -1
- package/lib/ui/markdown/index.js +18 -0
- package/lib/ui/markdown/index.js.map +1 -0
- package/lib/ui/markdown/markdown.js +40 -0
- package/lib/ui/markdown/markdown.js.map +1 -0
- package/lib/ui/markdown/markdown.module.css +7 -0
- package/lib/ui/skeleton/skeleton.module.css +3 -3
- package/lib/ui/tabs/tabs.module.css +1 -0
- package/lib/ui/textarea/textarea.js +2 -2
- package/lib/ui/textarea/textarea.js.map +1 -1
- package/lib/ui/textarea/textarea.module.css +0 -7
- package/lib-esm/components/bundle-assets/bundle-assets.js +1 -1
- package/lib-esm/components/bundle-assets/bundle-assets.js.map +1 -1
- package/lib-esm/components/insights/insights.module.css +1 -0
- package/lib-esm/components/metrics-table-export/metrics-table-export.js +3 -4
- package/lib-esm/components/metrics-table-export/metrics-table-export.js.map +1 -1
- package/lib-esm/components/preview-source/preview-source.js +8 -5
- package/lib-esm/components/preview-source/preview-source.js.map +1 -1
- package/lib-esm/components/preview-source/preview-source.module.css +12 -0
- package/lib-esm/css/variables.css +4 -0
- package/lib-esm/ui/dialog/dialog.module.css +3 -3
- package/lib-esm/ui/index.js +1 -0
- package/lib-esm/ui/index.js.map +1 -1
- package/lib-esm/ui/markdown/index.js +2 -0
- package/lib-esm/ui/markdown/index.js.map +1 -0
- package/lib-esm/ui/markdown/markdown.js +10 -0
- package/lib-esm/ui/markdown/markdown.js.map +1 -0
- package/lib-esm/ui/markdown/markdown.module.css +7 -0
- package/lib-esm/ui/skeleton/skeleton.module.css +3 -3
- package/lib-esm/ui/tabs/tabs.module.css +1 -0
- package/lib-esm/ui/textarea/textarea.js +2 -2
- package/lib-esm/ui/textarea/textarea.js.map +1 -1
- package/lib-esm/ui/textarea/textarea.module.css +0 -7
- package/package.json +10 -9
- package/src/components/bundle-assets/bundle-assets.jsx +6 -6
- package/src/components/insights/insights.module.css +1 -0
- package/src/components/metrics-table-export/metrics-table-export.tsx +4 -5
- package/src/components/preview-source/preview-source.module.css +12 -0
- package/src/components/preview-source/preview-source.stories.tsx +19 -1
- package/src/components/preview-source/preview-source.tsx +30 -21
- package/src/css/variables.css +4 -0
- package/src/ui/dialog/dialog.module.css +3 -3
- package/src/ui/index.js +1 -0
- package/src/ui/markdown/index.ts +1 -0
- package/src/ui/markdown/markdown.module.css +7 -0
- package/src/ui/markdown/markdown.stories.tsx +29 -0
- package/src/ui/markdown/markdown.tsx +24 -0
- package/src/ui/skeleton/skeleton.module.css +3 -3
- package/src/ui/tabs/tabs.module.css +1 -0
- package/src/ui/textarea/textarea.module.css +0 -7
- package/src/ui/textarea/textarea.tsx +2 -8
- package/types/components/preview-source/preview-source.d.ts +2 -1
- package/types/ui/index.d.ts +1 -0
- package/types/ui/markdown/index.d.ts +1 -0
- package/types/ui/markdown/markdown.d.ts +7 -0
- package/types/ui/textarea/textarea.d.ts +0 -1
- package/lib/components/metrics-table-export/metrics-table-export.module.css +0 -8
- package/lib-esm/components/metrics-table-export/metrics-table-export.module.css +0 -8
- package/src/components/metrics-table-export/metrics-table-export.module.css +0 -8
package/lib-esm/ui/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export { Icon } from './icon';
|
|
|
13
13
|
export { Input } from './input';
|
|
14
14
|
export { InputSearch } from './input-search';
|
|
15
15
|
export { Loader } from './loader';
|
|
16
|
+
export { Markdown } from './markdown';
|
|
16
17
|
export { Skeleton } from './skeleton';
|
|
17
18
|
export { Table } from './table';
|
|
18
19
|
export { Tabs } from './tabs';
|
package/lib-esm/ui/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ui/index.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ui/index.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ui/markdown/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import cx from 'classnames';
|
|
3
|
+
import snarkdown from 'snarkdown';
|
|
4
|
+
import css from './markdown.module.css';
|
|
5
|
+
export const Markdown = (props) => {
|
|
6
|
+
const { className = '', content = '', as: Component = 'div', ...restProps } = props;
|
|
7
|
+
const html = useMemo(() => snarkdown(content), [content]);
|
|
8
|
+
return (React.createElement(Component, { className: cx(css.root, className), ...restProps, dangerouslySetInnerHTML: { __html: html } }));
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../../src/ui/markdown/markdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAA+B,OAAO,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,GAAG,MAAM,uBAAuB,CAAC;AAOxC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAoB,EAAE,EAAE;IAC/C,MAAM,EAAE,SAAS,GAAG,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE,EAAE,SAAS,GAAG,KAAK,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IAEpF,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAE1D,OAAO,CACL,oBAAC,SAAS,IACR,SAAS,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,KAC9B,SAAS,EACb,uBAAuB,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,GACzC,CACH,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
.root {
|
|
2
|
-
background:
|
|
3
|
-
opacity:
|
|
2
|
+
background: var(--skeleton-inline-background);
|
|
3
|
+
opacity: var(--skeleton-opacity);
|
|
4
4
|
pointer-events: none;
|
|
5
5
|
min-width: 6em;
|
|
6
6
|
border-radius: var(--radius-medium);
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
.block {
|
|
17
|
-
background:
|
|
17
|
+
background: var(--skeleton-block-background);
|
|
18
18
|
}
|
|
@@ -2,8 +2,8 @@ import React from 'react';
|
|
|
2
2
|
import cx from 'classnames';
|
|
3
3
|
import css from './textarea.module.css';
|
|
4
4
|
export const Textarea = (props) => {
|
|
5
|
-
const { className = '',
|
|
6
|
-
const rootClassName = cx(css.root,
|
|
5
|
+
const { className = '', size = '', ...restProps } = props;
|
|
6
|
+
const rootClassName = cx(css.root, size && css[size], className);
|
|
7
7
|
return React.createElement("textarea", { className: rootClassName, ...restProps });
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=textarea.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textarea.js","sourceRoot":"","sources":["../../../src/ui/textarea/textarea.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,GAAG,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"textarea.js","sourceRoot":"","sources":["../../../src/ui/textarea/textarea.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,GAAG,MAAM,uBAAuB,CAAC;AAMxC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAoB,EAAE,EAAE;IAC/C,MAAM,EAAE,SAAS,GAAG,EAAE,EAAE,IAAI,GAAG,EAAE,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IAE1D,MAAM,aAAa,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC;IAEjE,OAAO,kCAAU,SAAS,EAAE,aAAa,KAAM,SAAS,GAAI,CAAC;AAC/D,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bundle-stats/ui",
|
|
3
|
-
"version": "4.16.0-beta.
|
|
3
|
+
"version": "4.16.0-beta.10",
|
|
4
4
|
"description": "UI components for BundleStats projects.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib-esm/index.js",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"@babel/preset-env": "7.25.7",
|
|
40
40
|
"@babel/preset-react": "7.25.7",
|
|
41
41
|
"@babel/preset-typescript": "7.25.7",
|
|
42
|
-
"@storybook/addon-essentials": "8.3.
|
|
42
|
+
"@storybook/addon-essentials": "8.3.5",
|
|
43
43
|
"@storybook/addon-webpack5-compiler-babel": "3.0.3",
|
|
44
|
-
"@storybook/react": "8.3.
|
|
45
|
-
"@storybook/react-webpack5": "8.3.
|
|
44
|
+
"@storybook/react": "8.3.5",
|
|
45
|
+
"@storybook/react-webpack5": "8.3.5",
|
|
46
46
|
"@types/d3": "7.4.3",
|
|
47
47
|
"@types/react": "18.3.11",
|
|
48
48
|
"@types/react-router-dom": "5.3.3",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"react-dom": "18.3.1",
|
|
62
62
|
"react-router-dom": "5.3.4",
|
|
63
63
|
"rimraf": "6.0.1",
|
|
64
|
-
"storybook": "8.3.
|
|
64
|
+
"storybook": "8.3.5",
|
|
65
65
|
"typescript": "5.6.2",
|
|
66
66
|
"typescript-plugin-css-modules": "5.1.0"
|
|
67
67
|
},
|
|
@@ -74,12 +74,13 @@
|
|
|
74
74
|
"react-router-dom": "^5.0.0"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@bundle-stats/utils": "^4.16.0-beta.
|
|
77
|
+
"@bundle-stats/utils": "^4.16.0-beta.10",
|
|
78
78
|
"ariakit": "2.0.0-next.44",
|
|
79
|
-
"d3": "
|
|
79
|
+
"d3": "7.9.0",
|
|
80
80
|
"modern-css-reset": "1.4.0",
|
|
81
|
-
"react-use": "
|
|
81
|
+
"react-use": "17.5.1",
|
|
82
|
+
"snarkdown": "2.0.0",
|
|
82
83
|
"use-query-params": "2.2.1"
|
|
83
84
|
},
|
|
84
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "cb616111c85f4b0d28e4b049fe3f6c7b0d7551d7"
|
|
85
86
|
}
|
|
@@ -52,10 +52,10 @@ const DISPLAY_TYPE_GROUPS = {
|
|
|
52
52
|
|
|
53
53
|
const getFileTypeFilters = (filters) =>
|
|
54
54
|
Object.entries(FILE_TYPE_LABELS).map(([key, label]) => ({
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
key,
|
|
56
|
+
label,
|
|
57
|
+
defaultValue: get(filters, `${ASSET_FILE_TYPE}.${key}`, true),
|
|
58
|
+
}));
|
|
59
59
|
|
|
60
60
|
const getFilters = ({ compareMode, filters }) => ({
|
|
61
61
|
[ASSET_FILTERS.CHANGED]: {
|
|
@@ -64,7 +64,7 @@ const getFilters = ({ compareMode, filters }) => ({
|
|
|
64
64
|
disabled: !compareMode,
|
|
65
65
|
},
|
|
66
66
|
[ASSET_ENTRY_TYPE]: {
|
|
67
|
-
label: '
|
|
67
|
+
label: 'Type',
|
|
68
68
|
children: [
|
|
69
69
|
{
|
|
70
70
|
key: ASSET_FILTERS.ENTRY,
|
|
@@ -396,7 +396,7 @@ export const BundleAssets = (props) => {
|
|
|
396
396
|
)}
|
|
397
397
|
|
|
398
398
|
<Dialog title={I18N.EXPORT} width="wide" state={exportDialog}>
|
|
399
|
-
{exportDialog.open && <MetricsTableExport items={items} download="bundle-stats--assets"/>}
|
|
399
|
+
{exportDialog.open && <MetricsTableExport items={items} download="bundle-stats--assets" />}
|
|
400
400
|
</Dialog>
|
|
401
401
|
</>
|
|
402
402
|
);
|
|
@@ -5,7 +5,6 @@ import type { ReportMetricRow } from '@bundle-stats/utils';
|
|
|
5
5
|
import { Stack } from '../../layout/stack';
|
|
6
6
|
import { Tabs } from '../../ui/tabs';
|
|
7
7
|
import { PreviewSource } from '../preview-source';
|
|
8
|
-
import css from './metrics-table-export.module.css';
|
|
9
8
|
|
|
10
9
|
const generateSourceJSON = (items: Array<ReportMetricRow>): string => {
|
|
11
10
|
const output = items.map((item) => ({
|
|
@@ -54,12 +53,12 @@ const SOURCES = [
|
|
|
54
53
|
{
|
|
55
54
|
label: 'CSV',
|
|
56
55
|
transformFn: generateSourceCSV,
|
|
57
|
-
extension: '
|
|
56
|
+
extension: 'csv',
|
|
58
57
|
},
|
|
59
58
|
{
|
|
60
59
|
label: 'JSON',
|
|
61
60
|
transformFn: generateSourceJSON,
|
|
62
|
-
extension: '
|
|
61
|
+
extension: 'json',
|
|
63
62
|
},
|
|
64
63
|
];
|
|
65
64
|
|
|
@@ -85,14 +84,14 @@ export const MetricsTableExport = (props: MetricsTableExportProps) => {
|
|
|
85
84
|
</Tabs.Item>
|
|
86
85
|
))}
|
|
87
86
|
</Tabs>
|
|
88
|
-
<div
|
|
87
|
+
<div>
|
|
89
88
|
{SOURCES.map(
|
|
90
89
|
(source) =>
|
|
91
90
|
selectedId === source.label && (
|
|
92
91
|
<PreviewSource
|
|
93
92
|
source={source.transformFn(items)}
|
|
93
|
+
rows={20}
|
|
94
94
|
download={`${download}.${source.extension}`}
|
|
95
|
-
className={css.panel}
|
|
96
95
|
key={source.label}
|
|
97
96
|
/>
|
|
98
97
|
),
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
z-index: 2;
|
|
8
8
|
top: var(--space-xsmall);
|
|
9
9
|
right: var(--space-xsmall);
|
|
10
|
+
background: var(--color-background);
|
|
11
|
+
border-radius: var(--radius-medium);
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
/** fix control group with nested components */
|
|
@@ -21,8 +23,18 @@
|
|
|
21
23
|
box-shadow: none;
|
|
22
24
|
}
|
|
23
25
|
|
|
26
|
+
/** Source content */
|
|
24
27
|
.content {
|
|
25
28
|
position: relative;
|
|
26
29
|
z-index: 1;
|
|
27
30
|
height: 100%;
|
|
31
|
+
background: var(--color-highlight);
|
|
32
|
+
color: var(--color-text);
|
|
33
|
+
font-family: var(--font-family-fixed);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Empty / loading state */
|
|
37
|
+
.isEmpty .content {
|
|
38
|
+
pointer-events: none;
|
|
39
|
+
background: var(--color-highlight);
|
|
28
40
|
}
|
|
@@ -29,7 +29,25 @@ const SOURCE = JSON.stringify(
|
|
|
29
29
|
|
|
30
30
|
export const Default: Story = {
|
|
31
31
|
args: {
|
|
32
|
-
source:
|
|
32
|
+
source: JSON.stringify(
|
|
33
|
+
[
|
|
34
|
+
{
|
|
35
|
+
label: 'Hey',
|
|
36
|
+
runs: [
|
|
37
|
+
{ value: 1, name: 'a' },
|
|
38
|
+
{ value: 2, name: 'b' },
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
null,
|
|
43
|
+
2,
|
|
44
|
+
),
|
|
45
|
+
download: 'bundle-stats--assets.json',
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const Empty: Story = {
|
|
50
|
+
args: {
|
|
33
51
|
download: 'bundle-stats--assets.json',
|
|
34
52
|
},
|
|
35
53
|
};
|
|
@@ -9,8 +9,14 @@ import { Tooltip } from '../../ui/tooltip';
|
|
|
9
9
|
import { Textarea } from '../../ui/textarea';
|
|
10
10
|
import css from './preview-source.module.css';
|
|
11
11
|
|
|
12
|
+
const DEFAULT_ROWS = 10;
|
|
13
|
+
|
|
12
14
|
type PreviewSourceProps = {
|
|
13
|
-
source
|
|
15
|
+
source?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Textarea rows
|
|
18
|
+
*/
|
|
19
|
+
rows?: number;
|
|
14
20
|
/**
|
|
15
21
|
* Link download attribute
|
|
16
22
|
* @example
|
|
@@ -20,28 +26,31 @@ type PreviewSourceProps = {
|
|
|
20
26
|
} & ComponentProps<'div'>;
|
|
21
27
|
|
|
22
28
|
export const PreviewSource = (props: PreviewSourceProps) => {
|
|
23
|
-
const { className = '', source, download = false, ...restProps } = props;
|
|
29
|
+
const { className = '', source, rows = DEFAULT_ROWS, download = false, ...restProps } = props;
|
|
30
|
+
|
|
31
|
+
const isEmpty = !source;
|
|
32
|
+
const rootClassName = cx(css.root, className, isEmpty && css.isEmpty);
|
|
24
33
|
|
|
25
34
|
return (
|
|
26
|
-
<div className={
|
|
27
|
-
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
<div className={rootClassName} {...restProps}>
|
|
36
|
+
{source && (
|
|
37
|
+
<ControlGroup className={css.toolbar}>
|
|
38
|
+
<CopyToClipboard outline size="small" text={source} />
|
|
39
|
+
{download && (
|
|
40
|
+
<Tooltip title={`Download ${download}`} className={css.downloadTooltip}>
|
|
41
|
+
<Button
|
|
42
|
+
outline
|
|
43
|
+
rightGlyph={BUTTON_GLYPHS.DOWNLOAD}
|
|
44
|
+
size="small"
|
|
45
|
+
as="a"
|
|
46
|
+
href={`data:application/json,${encodeURIComponent(source)}`}
|
|
47
|
+
download={download}
|
|
48
|
+
/>
|
|
49
|
+
</Tooltip>
|
|
50
|
+
)}
|
|
51
|
+
</ControlGroup>
|
|
52
|
+
)}
|
|
53
|
+
<Textarea readOnly rows={rows} value={source} className={css.content} />
|
|
45
54
|
</div>
|
|
46
55
|
);
|
|
47
56
|
};
|
package/src/css/variables.css
CHANGED
|
@@ -201,6 +201,10 @@
|
|
|
201
201
|
|
|
202
202
|
--outline-hover: 0 0 0 var(--space-xxxsmall) var(--color-highlight);
|
|
203
203
|
|
|
204
|
+
--skeleton-inline-background: linear-gradient(transparent 10%, currentColor 10.1%, currentColor 89.9%, transparent 90%);
|
|
205
|
+
--skeleton-block-background: currentColor;
|
|
206
|
+
--skeleton-opacity: 0.06;
|
|
207
|
+
|
|
204
208
|
/** Layout */
|
|
205
209
|
--max-width: 88rem;
|
|
206
210
|
--entry-info-width: 64rem;
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
|
|
62
62
|
/** Width variation */
|
|
63
63
|
.width--narrow {
|
|
64
|
-
max-width:
|
|
64
|
+
max-width: 360px;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
.width--medium {
|
|
68
|
-
max-width:
|
|
68
|
+
max-width: 640px;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
.width--wide {
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
.width--extra-wide {
|
|
76
|
-
max-width: var(--max-width);
|
|
76
|
+
max-width: calc(var(--max-width) + 2 * var(--space-medium));
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/** Center variation */
|
package/src/ui/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export { Icon } from './icon';
|
|
|
13
13
|
export { Input } from './input';
|
|
14
14
|
export { InputSearch } from './input-search';
|
|
15
15
|
export { Loader } from './loader';
|
|
16
|
+
export { Markdown } from './markdown';
|
|
16
17
|
export { Skeleton } from './skeleton';
|
|
17
18
|
export { Table } from './table';
|
|
18
19
|
export { Tabs } from './tabs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './markdown';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Markdown } from '.';
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof Markdown> = {
|
|
5
|
+
title: 'UI/Markdown',
|
|
6
|
+
component: Markdown,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default meta;
|
|
10
|
+
|
|
11
|
+
type Story = StoryObj<typeof meta>;
|
|
12
|
+
|
|
13
|
+
export const Default: Story = {
|
|
14
|
+
args: {
|
|
15
|
+
content: '**One line** _markdown_ content',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const MULTI_LINE_MARKDOWN = `
|
|
20
|
+
**Lorem ipsum** dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Habitant morbi tristique senectus et netus et malesuada.
|
|
21
|
+
|
|
22
|
+
Eget nunc scelerisque viverra mauris in. Ipsum dolor sit amet consectetur adipiscing.
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
export const MultiLine: Story = {
|
|
26
|
+
args: {
|
|
27
|
+
content: MULTI_LINE_MARKDOWN,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React, { ComponentProps, ElementType, useMemo } from 'react';
|
|
2
|
+
import cx from 'classnames';
|
|
3
|
+
import snarkdown from 'snarkdown';
|
|
4
|
+
|
|
5
|
+
import css from './markdown.module.css';
|
|
6
|
+
|
|
7
|
+
type MarkdownProps = {
|
|
8
|
+
content?: string;
|
|
9
|
+
as?: ElementType;
|
|
10
|
+
} & ComponentProps<'div'>;
|
|
11
|
+
|
|
12
|
+
export const Markdown = (props: MarkdownProps) => {
|
|
13
|
+
const { className = '', content = '', as: Component = 'div', ...restProps } = props;
|
|
14
|
+
|
|
15
|
+
const html = useMemo(() => snarkdown(content), [content]);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<Component
|
|
19
|
+
className={cx(css.root, className)}
|
|
20
|
+
{...restProps}
|
|
21
|
+
dangerouslySetInnerHTML={{ __html: html }}
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
.root {
|
|
2
|
-
background:
|
|
3
|
-
opacity:
|
|
2
|
+
background: var(--skeleton-inline-background);
|
|
3
|
+
opacity: var(--skeleton-opacity);
|
|
4
4
|
pointer-events: none;
|
|
5
5
|
min-width: 6em;
|
|
6
6
|
border-radius: var(--radius-medium);
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
.block {
|
|
17
|
-
background:
|
|
17
|
+
background: var(--skeleton-block-background);
|
|
18
18
|
}
|
|
@@ -5,19 +5,13 @@ import cx from 'classnames';
|
|
|
5
5
|
import css from './textarea.module.css';
|
|
6
6
|
|
|
7
7
|
export type TextareaProps = {
|
|
8
|
-
previewSource?: boolean;
|
|
9
8
|
size?: 'small' | 'medium' | 'large';
|
|
10
9
|
} & ComponentProps<'textarea'>;
|
|
11
10
|
|
|
12
11
|
export const Textarea = (props: TextareaProps) => {
|
|
13
|
-
const { className = '',
|
|
12
|
+
const { className = '', size = '', ...restProps } = props;
|
|
14
13
|
|
|
15
|
-
const rootClassName = cx(
|
|
16
|
-
css.root,
|
|
17
|
-
previewSource && css.previewSource,
|
|
18
|
-
size && css[size],
|
|
19
|
-
className,
|
|
20
|
-
);
|
|
14
|
+
const rootClassName = cx(css.root, size && css[size], className);
|
|
21
15
|
|
|
22
16
|
return <textarea className={rootClassName} {...restProps} />;
|
|
23
17
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ComponentProps } from 'react';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
type PreviewSourceProps = {
|
|
4
|
-
source
|
|
4
|
+
source?: string;
|
|
5
|
+
rows?: number;
|
|
5
6
|
download?: string;
|
|
6
7
|
} & ComponentProps<'div'>;
|
|
7
8
|
export declare const PreviewSource: (props: PreviewSourceProps) => React.JSX.Element;
|
package/types/ui/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export { Icon } from "./icon";
|
|
|
13
13
|
export { Input } from "./input";
|
|
14
14
|
export { InputSearch } from "./input-search";
|
|
15
15
|
export { Loader } from "./loader";
|
|
16
|
+
export { Markdown } from "./markdown";
|
|
16
17
|
export { Skeleton } from "./skeleton";
|
|
17
18
|
export { Table } from "./table";
|
|
18
19
|
export { Tabs } from "./tabs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './markdown';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ComponentProps } from 'react';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
export type TextareaProps = {
|
|
4
|
-
previewSource?: boolean;
|
|
5
4
|
size?: 'small' | 'medium' | 'large';
|
|
6
5
|
} & ComponentProps<'textarea'>;
|
|
7
6
|
export declare const Textarea: (props: TextareaProps) => React.JSX.Element;
|