@scality/core-ui 0.199.0 → 0.201.0
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/dist/components/buttonv2/Buttonv2.component.d.ts.map +1 -1
- package/dist/components/buttonv2/Buttonv2.component.js +9 -5
- package/dist/components/buttonv2/CopyButton.component.d.ts +1 -1
- package/dist/components/buttonv2/CopyButton.component.d.ts.map +1 -1
- package/dist/components/buttonv2/CopyButton.component.js +25 -15
- package/dist/components/editor/Editor.component.d.ts +17 -0
- package/dist/components/editor/Editor.component.d.ts.map +1 -0
- package/dist/components/editor/Editor.component.js +118 -0
- package/dist/components/editor/editorTheme.d.ts +5 -0
- package/dist/components/editor/editorTheme.d.ts.map +1 -0
- package/dist/components/editor/editorTheme.js +115 -0
- package/dist/components/editor/index.d.ts +3 -0
- package/dist/components/editor/index.d.ts.map +1 -0
- package/dist/components/editor/index.js +1 -0
- package/dist/components/iconhelper/IconHelper.d.ts.map +1 -1
- package/dist/components/iconhelper/IconHelper.js +0 -1
- package/dist/components/navbar/Navbar.component.d.ts.map +1 -1
- package/dist/components/navbar/Navbar.component.js +15 -10
- package/dist/next.d.ts +2 -0
- package/dist/next.d.ts.map +1 -1
- package/dist/next.js +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +24 -0
- package/package.json +7 -1
- package/src/lib/components/buttonv2/Buttonv2.component.tsx +8 -5
- package/src/lib/components/buttonv2/CopyButton.component.test.tsx +252 -0
- package/src/lib/components/buttonv2/CopyButton.component.tsx +28 -21
- package/src/lib/components/editor/Editor.component.tsx +163 -0
- package/src/lib/components/editor/Editor.test.tsx +295 -0
- package/src/lib/components/editor/editorTheme.ts +126 -0
- package/src/lib/components/editor/index.ts +2 -0
- package/src/lib/components/iconhelper/IconHelper.tsx +0 -1
- package/src/lib/components/navbar/Navbar.component.tsx +15 -10
- package/src/lib/next.ts +2 -0
- package/src/lib/utils.test.ts +48 -0
- package/src/lib/utils.ts +32 -0
- package/stories/editor.stories.tsx +132 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Editor, EditorProps } from '../src/lib/next';
|
|
3
|
+
|
|
4
|
+
const sampleJson = JSON.stringify(
|
|
5
|
+
{
|
|
6
|
+
Version: '2012-10-17',
|
|
7
|
+
Statement: [
|
|
8
|
+
{
|
|
9
|
+
Sid: 'ExampleStatement',
|
|
10
|
+
Effect: 'Allow',
|
|
11
|
+
Principal: '*',
|
|
12
|
+
Action: 's3:GetObject',
|
|
13
|
+
Resource: 'arn:aws:s3:::my-bucket/*',
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
null,
|
|
18
|
+
2,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const invalidJson = JSON.stringify(
|
|
22
|
+
{
|
|
23
|
+
Version: 'invalid-version',
|
|
24
|
+
Statement: [
|
|
25
|
+
{
|
|
26
|
+
Sid: 'Test',
|
|
27
|
+
Effect: 'InvalidEffect',
|
|
28
|
+
Principal: '*',
|
|
29
|
+
Action: 's3:GetObject',
|
|
30
|
+
Resource: 'arn:aws:s3:::my-bucket/*',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
null,
|
|
35
|
+
2,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const policySchema = {
|
|
39
|
+
type: 'object' as const,
|
|
40
|
+
required: ['Version', 'Statement'],
|
|
41
|
+
properties: {
|
|
42
|
+
Version: {
|
|
43
|
+
type: 'string' as const,
|
|
44
|
+
enum: ['2012-10-17', '2008-10-17'],
|
|
45
|
+
},
|
|
46
|
+
Statement: {
|
|
47
|
+
type: 'array' as const,
|
|
48
|
+
minItems: 1,
|
|
49
|
+
items: {
|
|
50
|
+
type: 'object' as const,
|
|
51
|
+
required: ['Effect', 'Principal', 'Action', 'Resource'],
|
|
52
|
+
properties: {
|
|
53
|
+
Sid: { type: 'string' as const },
|
|
54
|
+
Effect: { type: 'string' as const, enum: ['Allow', 'Deny'] },
|
|
55
|
+
Principal: { type: 'string' as const },
|
|
56
|
+
Action: { type: 'string' as const },
|
|
57
|
+
Resource: { type: 'string' as const },
|
|
58
|
+
},
|
|
59
|
+
additionalProperties: false,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default {
|
|
66
|
+
title: 'Components/Inputs/Editor',
|
|
67
|
+
component: Editor,
|
|
68
|
+
argTypes: {
|
|
69
|
+
readOnly: { control: 'boolean' },
|
|
70
|
+
height: { control: 'text' },
|
|
71
|
+
width: { control: 'text' },
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const EditorWithState = (args: EditorProps) => {
|
|
76
|
+
const [value, setValue] = useState(args.value || sampleJson);
|
|
77
|
+
return <Editor {...args} value={value} onChange={setValue} />;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const Default = {
|
|
81
|
+
render: (args: EditorProps) => <EditorWithState {...args} />,
|
|
82
|
+
args: {
|
|
83
|
+
value: sampleJson,
|
|
84
|
+
height: '400px',
|
|
85
|
+
width: '100%',
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const ReadOnly = {
|
|
90
|
+
render: (args: EditorProps) => <EditorWithState {...args} />,
|
|
91
|
+
args: {
|
|
92
|
+
value: sampleJson,
|
|
93
|
+
readOnly: true,
|
|
94
|
+
height: '400px',
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Pass `language` as an object with a `schema` to enable
|
|
100
|
+
* validation, autocompletion, and hover tooltips from the schema.
|
|
101
|
+
*
|
|
102
|
+
* Hover over the red-underlined values to see error messages.
|
|
103
|
+
*/
|
|
104
|
+
export const WithSchemaValidation = {
|
|
105
|
+
render: (args: EditorProps) => <EditorWithState {...args} />,
|
|
106
|
+
args: {
|
|
107
|
+
value: invalidJson,
|
|
108
|
+
language: { name: 'json', schema: policySchema },
|
|
109
|
+
height: '400px',
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Valid JSON with schema — no errors shown, but autocompletion is active.
|
|
115
|
+
*/
|
|
116
|
+
export const ValidWithSchema = {
|
|
117
|
+
render: (args: EditorProps) => <EditorWithState {...args} />,
|
|
118
|
+
args: {
|
|
119
|
+
value: sampleJson,
|
|
120
|
+
language: { name: 'json', schema: policySchema },
|
|
121
|
+
height: '400px',
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export const CustomDimensions = {
|
|
126
|
+
render: (args: EditorProps) => <EditorWithState {...args} />,
|
|
127
|
+
args: {
|
|
128
|
+
value: '{\n "compact": true\n}',
|
|
129
|
+
height: '200px',
|
|
130
|
+
width: '400px',
|
|
131
|
+
},
|
|
132
|
+
};
|