superdesk-ui-framework 6.0.1 → 6.0.3
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/app-typescript/components/DatePicker.tsx +9 -2
- package/app-typescript/components/StateLabel.tsx +81 -0
- package/app-typescript/index.ts +1 -0
- package/dist/components/Index.tsx +5 -0
- package/dist/components/StateLabel.tsx +201 -0
- package/dist/examples.bundle.js +2256 -2002
- package/dist/superdesk-ui.bundle.js +1806 -1689
- package/dist/vendor.bundle.js +13 -13
- package/package.json +1 -1
- package/react/components/DatePicker.js +9 -2
- package/react/components/StateLabel.d.ts +21 -0
- package/react/components/StateLabel.js +100 -0
- package/react/index.d.ts +1 -0
- package/react/index.js +5 -3
|
@@ -337,6 +337,13 @@ export class DatePickerISO extends React.PureComponent<IDatePickerISO> {
|
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
+
function getOptionLabel(options: Array<{id: string; label?: string}>, id: string | null | undefined): string {
|
|
341
|
+
if (id == null) {
|
|
342
|
+
return '';
|
|
343
|
+
}
|
|
344
|
+
return options.find((option) => option.id === id)?.label ?? id;
|
|
345
|
+
}
|
|
346
|
+
|
|
340
347
|
const MonthNavigator = ({
|
|
341
348
|
value,
|
|
342
349
|
options,
|
|
@@ -346,7 +353,7 @@ const MonthNavigator = ({
|
|
|
346
353
|
kind="synchronous"
|
|
347
354
|
value={[value]}
|
|
348
355
|
getOptions={() => options.map((option) => ({value: option.id}))}
|
|
349
|
-
getLabel={(
|
|
356
|
+
getLabel={(optionId) => getOptionLabel(options, optionId)}
|
|
350
357
|
getId={(option) => option}
|
|
351
358
|
onChange={(selected) => {
|
|
352
359
|
onChange(selected[0]);
|
|
@@ -355,7 +362,7 @@ const MonthNavigator = ({
|
|
|
355
362
|
labelHidden
|
|
356
363
|
valueTemplate={(item) => (
|
|
357
364
|
<div className="sd-datepicker__navigator-value sd-datepicker__navigator-month">
|
|
358
|
-
<div>{options
|
|
365
|
+
<div>{getOptionLabel(options, item)}</div>
|
|
359
366
|
<Icon name="chevron-down-thin" />
|
|
360
367
|
</div>
|
|
361
368
|
)}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {Label} from './Label';
|
|
3
|
+
|
|
4
|
+
type StateType =
|
|
5
|
+
| 'draft'
|
|
6
|
+
| 'ingested'
|
|
7
|
+
| 'routed'
|
|
8
|
+
| 'fetched'
|
|
9
|
+
| 'submitted'
|
|
10
|
+
| 'in_progress'
|
|
11
|
+
| 'published'
|
|
12
|
+
| 'spiked'
|
|
13
|
+
| 'scheduled'
|
|
14
|
+
| 'corrected'
|
|
15
|
+
| 'killed'
|
|
16
|
+
| 'recalled'
|
|
17
|
+
| 'unpublished'
|
|
18
|
+
| 'correction'
|
|
19
|
+
| 'being_corrected'
|
|
20
|
+
| string;
|
|
21
|
+
|
|
22
|
+
interface IStateColorConfig {
|
|
23
|
+
type?: 'default' | 'primary' | 'success' | 'warning' | 'alert' | 'highlight' | 'sd-green';
|
|
24
|
+
color?: string;
|
|
25
|
+
style?: 'filled' | 'hollow';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const DEFAULT_STATE_COLOR_MAP: Record<string, IStateColorConfig> = {
|
|
29
|
+
draft: {type: 'default', style: 'hollow'},
|
|
30
|
+
ingested: {type: 'primary', style: 'hollow'},
|
|
31
|
+
routed: {type: 'primary', style: 'hollow'},
|
|
32
|
+
fetched: {type: 'primary', style: 'hollow'},
|
|
33
|
+
submitted: {type: 'warning', style: 'hollow'},
|
|
34
|
+
in_progress: {type: 'warning', style: 'hollow'},
|
|
35
|
+
published: {type: 'success', style: 'hollow'},
|
|
36
|
+
spiked: {type: 'alert', style: 'hollow'},
|
|
37
|
+
recalled: {type: 'alert', style: 'hollow'},
|
|
38
|
+
killed: {type: 'alert', style: 'hollow'},
|
|
39
|
+
scheduled: {type: 'highlight', style: 'hollow'},
|
|
40
|
+
corrected: {type: 'sd-green', style: 'hollow'},
|
|
41
|
+
correction: {color: 'pink--500', style: 'filled'},
|
|
42
|
+
being_corrected: {color: 'pink--500', style: 'hollow'},
|
|
43
|
+
unpublished: {type: 'alert', style: 'hollow'},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
interface IProps {
|
|
47
|
+
state: StateType;
|
|
48
|
+
text: string;
|
|
49
|
+
onClick?: () => void;
|
|
50
|
+
color?: string;
|
|
51
|
+
noTransform?: boolean;
|
|
52
|
+
size?: 'small' | 'normal' | 'large';
|
|
53
|
+
mappingOverride?: Partial<Record<StateType, IStateColorConfig>>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class StateLabel extends React.PureComponent<IProps> {
|
|
57
|
+
private getColorConfig(state: StateType): IStateColorConfig {
|
|
58
|
+
const {mappingOverride} = this.props;
|
|
59
|
+
const override = mappingOverride?.[state];
|
|
60
|
+
const defaultConfig = DEFAULT_STATE_COLOR_MAP[state] || {type: 'default'};
|
|
61
|
+
|
|
62
|
+
return override ? {...defaultConfig, ...override} : defaultConfig;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
render() {
|
|
66
|
+
const {state, text, onClick, color, noTransform, size} = this.props;
|
|
67
|
+
const colorConfig = this.getColorConfig(state);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<Label
|
|
71
|
+
text={text}
|
|
72
|
+
type={color ? undefined : colorConfig.type}
|
|
73
|
+
color={color || colorConfig.color}
|
|
74
|
+
style={colorConfig.style || 'hollow'}
|
|
75
|
+
onClick={onClick}
|
|
76
|
+
noTransform={noTransform}
|
|
77
|
+
size={size}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
package/app-typescript/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ export {SelectWithTemplate} from './components/SelectWithTemplate';
|
|
|
11
11
|
export {WithPagination} from './components/WithPagination';
|
|
12
12
|
export {Popover} from './components/Popover';
|
|
13
13
|
export {Label} from './components/Label';
|
|
14
|
+
export {StateLabel} from './components/StateLabel';
|
|
14
15
|
export {Card} from './components/Card';
|
|
15
16
|
export {Badge} from './components/Badge';
|
|
16
17
|
export {Alert} from './components/Alert';
|
|
@@ -11,6 +11,7 @@ import AutocompleteDoc from './Autocomplete';
|
|
|
11
11
|
import SelectsDoc from './Selects';
|
|
12
12
|
import ButtonsDoc from './Buttons';
|
|
13
13
|
import LabelsDoc from './Labels';
|
|
14
|
+
import StateLabelDoc from './StateLabel';
|
|
14
15
|
import ButtonGroupsDoc from './ButtonGroups';
|
|
15
16
|
import BadgesDoc from './Badges';
|
|
16
17
|
import AlertDoc from './Alerts';
|
|
@@ -126,6 +127,10 @@ const pages: IPages = {
|
|
|
126
127
|
name: 'Labels',
|
|
127
128
|
component: LabelsDoc,
|
|
128
129
|
},
|
|
130
|
+
'state-label': {
|
|
131
|
+
name: 'State Labels',
|
|
132
|
+
component: StateLabelDoc,
|
|
133
|
+
},
|
|
129
134
|
'icon-labels': {
|
|
130
135
|
name: 'Icon Labels',
|
|
131
136
|
component: IconLabelDoc,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as Markup from '../../js/react';
|
|
3
|
+
import {StateLabel, Prop, PropsList} from '../../../app-typescript';
|
|
4
|
+
|
|
5
|
+
export default class StateLabelDoc extends React.Component {
|
|
6
|
+
render() {
|
|
7
|
+
return (
|
|
8
|
+
<section className="docs-page__container">
|
|
9
|
+
<h2 className="docs-page__h2">State Label</h2>
|
|
10
|
+
<Markup.ReactMarkupCodePreview>
|
|
11
|
+
{`
|
|
12
|
+
<StateLabel state="published" text="Published" />
|
|
13
|
+
`}
|
|
14
|
+
</Markup.ReactMarkupCodePreview>
|
|
15
|
+
<p className="docs-page__paragraph">
|
|
16
|
+
Display item states with predefined semantic colors. Currently supports 15 states with automatic
|
|
17
|
+
color mapping.
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
<h3 className="docs-page__h3">All States</h3>
|
|
21
|
+
<Markup.ReactMarkup>
|
|
22
|
+
<Markup.ReactMarkupPreview>
|
|
23
|
+
<div className="docs-page__content-row">
|
|
24
|
+
<div style={{display: 'flex', gap: '8px', flexWrap: 'wrap', alignItems: 'center'}}>
|
|
25
|
+
<StateLabel state="draft" text="Draft" />
|
|
26
|
+
<StateLabel state="ingested" text="Ingested" />
|
|
27
|
+
<StateLabel state="routed" text="Routed" />
|
|
28
|
+
<StateLabel state="fetched" text="Fetched" />
|
|
29
|
+
<StateLabel state="submitted" text="Submitted" />
|
|
30
|
+
<StateLabel state="in_progress" text="In Progress" />
|
|
31
|
+
<StateLabel state="published" text="Published" />
|
|
32
|
+
<StateLabel state="spiked" text="Spiked" />
|
|
33
|
+
<StateLabel state="recalled" text="Recalled" />
|
|
34
|
+
<StateLabel state="killed" text="Killed" />
|
|
35
|
+
<StateLabel state="scheduled" text="Scheduled" />
|
|
36
|
+
<StateLabel state="corrected" text="Corrected" />
|
|
37
|
+
<StateLabel state="correction" text="Correction" />
|
|
38
|
+
<StateLabel state="being_corrected" text="Being Corrected" />
|
|
39
|
+
<StateLabel state="unpublished" text="Unpublished" />
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
</Markup.ReactMarkupPreview>
|
|
43
|
+
<Markup.ReactMarkupCode>
|
|
44
|
+
{`
|
|
45
|
+
<StateLabel state="draft" text="Draft" />
|
|
46
|
+
<StateLabel state="ingested" text="Ingested" />
|
|
47
|
+
<StateLabel state="routed" text="Routed" />
|
|
48
|
+
<StateLabel state="fetched" text="Fetched" />
|
|
49
|
+
<StateLabel state="submitted" text="Submitted" />
|
|
50
|
+
<StateLabel state="in_progress" text="In Progress" />
|
|
51
|
+
<StateLabel state="published" text="Published" />
|
|
52
|
+
<StateLabel state="spiked" text="Spiked" />
|
|
53
|
+
<StateLabel state="recalled" text="Recalled" />
|
|
54
|
+
<StateLabel state="killed" text="Killed" />
|
|
55
|
+
<StateLabel state="scheduled" text="Scheduled" />
|
|
56
|
+
<StateLabel state="corrected" text="Corrected" />
|
|
57
|
+
<StateLabel state="correction" text="Correction" />
|
|
58
|
+
<StateLabel state="being_corrected" text="Being Corrected" />
|
|
59
|
+
<StateLabel state="unpublished" text="Unpublished" />
|
|
60
|
+
`}
|
|
61
|
+
</Markup.ReactMarkupCode>
|
|
62
|
+
</Markup.ReactMarkup>
|
|
63
|
+
|
|
64
|
+
<h3 className="docs-page__h3">With Click Handler</h3>
|
|
65
|
+
<Markup.ReactMarkup>
|
|
66
|
+
<Markup.ReactMarkupPreview>
|
|
67
|
+
<div className="docs-page__content-row">
|
|
68
|
+
<StateLabel
|
|
69
|
+
state="being_corrected"
|
|
70
|
+
text="Click me to open article"
|
|
71
|
+
onClick={() => alert('Article opened!')}
|
|
72
|
+
/>
|
|
73
|
+
</div>
|
|
74
|
+
</Markup.ReactMarkupPreview>
|
|
75
|
+
<Markup.ReactMarkupCode>
|
|
76
|
+
{`
|
|
77
|
+
<StateLabel
|
|
78
|
+
state="being_corrected"
|
|
79
|
+
text="Click me to open article"
|
|
80
|
+
onClick={() => alert('Article opened!')}
|
|
81
|
+
/>
|
|
82
|
+
`}
|
|
83
|
+
</Markup.ReactMarkupCode>
|
|
84
|
+
</Markup.ReactMarkup>
|
|
85
|
+
|
|
86
|
+
<h3 className="docs-page__h3">Different Sizes</h3>
|
|
87
|
+
<Markup.ReactMarkup>
|
|
88
|
+
<Markup.ReactMarkupPreview>
|
|
89
|
+
<div className="docs-page__content-row">
|
|
90
|
+
<div style={{display: 'flex', gap: '8px', flexWrap: 'wrap', alignItems: 'center'}}>
|
|
91
|
+
<StateLabel state="published" text="Small" size="small" />
|
|
92
|
+
<StateLabel state="published" text="Normal" size="normal" />
|
|
93
|
+
<StateLabel state="published" text="Large" size="large" />
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
</Markup.ReactMarkupPreview>
|
|
97
|
+
<Markup.ReactMarkupCode>
|
|
98
|
+
{`
|
|
99
|
+
<StateLabel state="published" text="Small" size="small" />
|
|
100
|
+
<StateLabel state="published" text="Normal" size="normal" />
|
|
101
|
+
<StateLabel state="published" text="Large" size="large" />
|
|
102
|
+
`}
|
|
103
|
+
</Markup.ReactMarkupCode>
|
|
104
|
+
</Markup.ReactMarkup>
|
|
105
|
+
|
|
106
|
+
<h3 className="docs-page__h3">Custom State Mapping</h3>
|
|
107
|
+
<p className="docs-page__paragraph">
|
|
108
|
+
Override default state-to-color mapping or define custom states with their own colors and styles.
|
|
109
|
+
</p>
|
|
110
|
+
<Markup.ReactMarkup>
|
|
111
|
+
<Markup.ReactMarkupPreview>
|
|
112
|
+
<div className="docs-page__content-row">
|
|
113
|
+
<div style={{display: 'flex', gap: '8px', flexWrap: 'wrap', alignItems: 'center'}}>
|
|
114
|
+
<StateLabel state="draft" text="Draft (Default)" />
|
|
115
|
+
<StateLabel
|
|
116
|
+
state="draft"
|
|
117
|
+
text="Draft (Custom Alert)"
|
|
118
|
+
mappingOverride={{
|
|
119
|
+
draft: {type: 'alert', style: 'hollow'},
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
122
|
+
<StateLabel
|
|
123
|
+
state="archived"
|
|
124
|
+
text="Archived"
|
|
125
|
+
mappingOverride={{
|
|
126
|
+
archived: {color: 'gray--500', style: 'hollow'},
|
|
127
|
+
}}
|
|
128
|
+
/>
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
</Markup.ReactMarkupPreview>
|
|
132
|
+
<Markup.ReactMarkupCode>
|
|
133
|
+
{`
|
|
134
|
+
{/* Predefined state with default mapping */}
|
|
135
|
+
<StateLabel state="draft" text="Draft (Default)" />
|
|
136
|
+
|
|
137
|
+
{/* Override predefined state mapping */}
|
|
138
|
+
<StateLabel
|
|
139
|
+
state="draft"
|
|
140
|
+
text="Draft (Custom Alert)"
|
|
141
|
+
mappingOverride={{
|
|
142
|
+
draft: {type: 'alert', style: 'hollow'}
|
|
143
|
+
}}
|
|
144
|
+
/>
|
|
145
|
+
|
|
146
|
+
{/* Custom state with mapping */}
|
|
147
|
+
<StateLabel
|
|
148
|
+
state="archived"
|
|
149
|
+
text="Archived"
|
|
150
|
+
mappingOverride={{
|
|
151
|
+
archived: {color: 'gray--500', style: 'hollow'}
|
|
152
|
+
}}
|
|
153
|
+
/>
|
|
154
|
+
`}
|
|
155
|
+
</Markup.ReactMarkupCode>
|
|
156
|
+
</Markup.ReactMarkup>
|
|
157
|
+
|
|
158
|
+
<h3 className="docs-page__h3">Props</h3>
|
|
159
|
+
<PropsList>
|
|
160
|
+
<Prop
|
|
161
|
+
name="state"
|
|
162
|
+
isRequired={true}
|
|
163
|
+
type="StateType"
|
|
164
|
+
default="/"
|
|
165
|
+
description="The item state value. One of 15 predefined states (draft, published, etc.) or any custom state string"
|
|
166
|
+
/>
|
|
167
|
+
<Prop name="text" isRequired={true} type="string" default="/" description="Label text to display" />
|
|
168
|
+
<Prop name="onClick" isRequired={false} type="() => void" default="/" description="Click handler" />
|
|
169
|
+
<Prop
|
|
170
|
+
name="color"
|
|
171
|
+
isRequired={false}
|
|
172
|
+
type="string"
|
|
173
|
+
default="/"
|
|
174
|
+
description="Custom color override (e.g. red--500); NOTE: When defined, it overrides the state's predefined color"
|
|
175
|
+
/>
|
|
176
|
+
<Prop
|
|
177
|
+
name="size"
|
|
178
|
+
isRequired={false}
|
|
179
|
+
type="small | normal | large"
|
|
180
|
+
default="normal"
|
|
181
|
+
description="Label size"
|
|
182
|
+
/>
|
|
183
|
+
<Prop
|
|
184
|
+
name="noTransform"
|
|
185
|
+
isRequired={false}
|
|
186
|
+
type="boolean"
|
|
187
|
+
default="false"
|
|
188
|
+
description="Disable uppercase text transformation"
|
|
189
|
+
/>
|
|
190
|
+
<Prop
|
|
191
|
+
name="mappingOverride"
|
|
192
|
+
isRequired={false}
|
|
193
|
+
type="Partial<Record<StateType, IStateColorConfig>>"
|
|
194
|
+
default="undefined"
|
|
195
|
+
description="Override or define state-to-color mapping. Works with predefined and custom states"
|
|
196
|
+
/>
|
|
197
|
+
</PropsList>
|
|
198
|
+
</section>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
}
|