@cratis/scene.blueprint.default 4.31.0 → 4.32.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/ComponentName.ts +12 -0
- package/defaultBlueprint.ts +2 -1
- package/defaultBlueprintComponentMetadata.ts +2 -0
- package/defaultBlueprintComponents.ts +5 -0
- package/dist/cjs/ComponentName.js +4 -0
- package/dist/cjs/ComponentName.js.map +1 -1
- package/dist/cjs/defaultBlueprint.js +9 -5
- package/dist/cjs/defaultBlueprint.js.map +1 -1
- package/dist/cjs/defaultBlueprintComponentMetadata.js +8 -0
- package/dist/cjs/defaultBlueprintComponentMetadata.js.map +1 -1
- package/dist/cjs/defaultBlueprintComponents.js +13 -1
- package/dist/cjs/defaultBlueprintComponents.js.map +1 -1
- package/dist/cjs/foundation/ActionButton.js +33 -0
- package/dist/cjs/foundation/ActionButton.js.map +1 -0
- package/dist/cjs/foundation/ComponentState.js +42 -0
- package/dist/cjs/foundation/ComponentState.js.map +1 -0
- package/dist/cjs/foundation/EmptyState.js +31 -0
- package/dist/cjs/foundation/EmptyState.js.map +1 -0
- package/dist/cjs/foundation/FoundationIcon.js +58 -0
- package/dist/cjs/foundation/FoundationIcon.js.map +1 -0
- package/dist/cjs/foundation/FoundationStates.js +62 -0
- package/dist/cjs/foundation/FoundationStates.js.map +1 -0
- package/dist/cjs/foundation/PermissionRule.js +22 -0
- package/dist/cjs/foundation/PermissionRule.js.map +1 -0
- package/dist/cjs/foundation/StatCard.js +61 -0
- package/dist/cjs/foundation/StatCard.js.map +1 -0
- package/dist/cjs/foundation/StateFrame.js +200 -0
- package/dist/cjs/foundation/StateFrame.js.map +1 -0
- package/dist/cjs/foundation/StatusChip.js +64 -0
- package/dist/cjs/foundation/StatusChip.js.map +1 -0
- package/dist/cjs/foundation/TrendChip.js +93 -0
- package/dist/cjs/foundation/TrendChip.js.map +1 -0
- package/dist/cjs/foundation/formatting.js +85 -0
- package/dist/cjs/foundation/formatting.js.map +1 -0
- package/dist/cjs/foundation/foundationComponentMetadata.js +41 -0
- package/dist/cjs/foundation/foundationComponentMetadata.js.map +1 -0
- package/dist/cjs/foundation/foundationDescriptors.js +232 -0
- package/dist/cjs/foundation/foundationDescriptors.js.map +1 -0
- package/dist/cjs/foundation/foundationSamples.js +71 -0
- package/dist/cjs/foundation/foundationSamples.js.map +1 -0
- package/dist/cjs/foundation/foundationStrings.js +105 -0
- package/dist/cjs/foundation/foundationStrings.js.map +1 -0
- package/dist/cjs/index.js +52 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/themes/dark.js +9 -1
- package/dist/cjs/themes/dark.js.map +1 -1
- package/dist/cjs/themes/light.js +10 -2
- package/dist/cjs/themes/light.js.map +1 -1
- package/dist/esm/ComponentName.d.ts +5 -1
- package/dist/esm/ComponentName.d.ts.map +1 -1
- package/dist/esm/ComponentName.js +4 -0
- package/dist/esm/ComponentName.js.map +1 -1
- package/dist/esm/defaultBlueprint.d.ts.map +1 -1
- package/dist/esm/defaultBlueprint.js +9 -5
- package/dist/esm/defaultBlueprint.js.map +1 -1
- package/dist/esm/defaultBlueprintComponentMetadata.d.ts.map +1 -1
- package/dist/esm/defaultBlueprintComponentMetadata.js +8 -0
- package/dist/esm/defaultBlueprintComponentMetadata.js.map +1 -1
- package/dist/esm/defaultBlueprintComponents.d.ts.map +1 -1
- package/dist/esm/defaultBlueprintComponents.js +13 -1
- package/dist/esm/defaultBlueprintComponents.js.map +1 -1
- package/dist/esm/foundation/ActionButton.d.ts +13 -0
- package/dist/esm/foundation/ActionButton.d.ts.map +1 -0
- package/dist/esm/foundation/ActionButton.js +31 -0
- package/dist/esm/foundation/ActionButton.js.map +1 -0
- package/dist/esm/foundation/ComponentState.d.ts +12 -0
- package/dist/esm/foundation/ComponentState.d.ts.map +1 -0
- package/dist/esm/foundation/ComponentState.js +38 -0
- package/dist/esm/foundation/ComponentState.js.map +1 -0
- package/dist/esm/foundation/EmptyState.d.ts +3 -0
- package/dist/esm/foundation/EmptyState.d.ts.map +1 -0
- package/dist/esm/foundation/EmptyState.js +29 -0
- package/dist/esm/foundation/EmptyState.js.map +1 -0
- package/dist/esm/foundation/Foundation.stories.d.ts +21 -0
- package/dist/esm/foundation/Foundation.stories.d.ts.map +1 -0
- package/dist/esm/foundation/Foundation.stories.js +18 -0
- package/dist/esm/foundation/Foundation.stories.js.map +1 -0
- package/dist/esm/foundation/FoundationIcon.d.ts +7 -0
- package/dist/esm/foundation/FoundationIcon.d.ts.map +1 -0
- package/dist/esm/foundation/FoundationIcon.js +55 -0
- package/dist/esm/foundation/FoundationIcon.js.map +1 -0
- package/dist/esm/foundation/FoundationStates.d.ts +8 -0
- package/dist/esm/foundation/FoundationStates.d.ts.map +1 -0
- package/dist/esm/foundation/FoundationStates.js +60 -0
- package/dist/esm/foundation/FoundationStates.js.map +1 -0
- package/dist/esm/foundation/PermissionRule.d.ts +8 -0
- package/dist/esm/foundation/PermissionRule.d.ts.map +1 -0
- package/dist/esm/foundation/PermissionRule.js +19 -0
- package/dist/esm/foundation/PermissionRule.js.map +1 -0
- package/dist/esm/foundation/StatCard.d.ts +3 -0
- package/dist/esm/foundation/StatCard.d.ts.map +1 -0
- package/dist/esm/foundation/StatCard.js +59 -0
- package/dist/esm/foundation/StatCard.js.map +1 -0
- package/dist/esm/foundation/StateFrame.d.ts +15 -0
- package/dist/esm/foundation/StateFrame.d.ts.map +1 -0
- package/dist/esm/foundation/StateFrame.js +197 -0
- package/dist/esm/foundation/StateFrame.js.map +1 -0
- package/dist/esm/foundation/StatusChip.d.ts +13 -0
- package/dist/esm/foundation/StatusChip.d.ts.map +1 -0
- package/dist/esm/foundation/StatusChip.js +59 -0
- package/dist/esm/foundation/StatusChip.js.map +1 -0
- package/dist/esm/foundation/TrendChip.d.ts +18 -0
- package/dist/esm/foundation/TrendChip.d.ts.map +1 -0
- package/dist/esm/foundation/TrendChip.js +88 -0
- package/dist/esm/foundation/TrendChip.js.map +1 -0
- package/dist/esm/foundation/formatting.d.ts +13 -0
- package/dist/esm/foundation/formatting.d.ts.map +1 -0
- package/dist/esm/foundation/formatting.js +78 -0
- package/dist/esm/foundation/formatting.js.map +1 -0
- package/dist/esm/foundation/foundationComponentMetadata.d.ts +3 -0
- package/dist/esm/foundation/foundationComponentMetadata.d.ts.map +1 -0
- package/dist/esm/foundation/foundationComponentMetadata.js +39 -0
- package/dist/esm/foundation/foundationComponentMetadata.js.map +1 -0
- package/dist/esm/foundation/foundationDescriptors.d.ts +6 -0
- package/dist/esm/foundation/foundationDescriptors.d.ts.map +1 -0
- package/dist/esm/foundation/foundationDescriptors.js +227 -0
- package/dist/esm/foundation/foundationDescriptors.js.map +1 -0
- package/dist/esm/foundation/foundationSamples.d.ts +10 -0
- package/dist/esm/foundation/foundationSamples.d.ts.map +1 -0
- package/dist/esm/foundation/foundationSamples.js +68 -0
- package/dist/esm/foundation/foundationSamples.js.map +1 -0
- package/dist/esm/foundation/foundationStrings.d.ts +78 -0
- package/dist/esm/foundation/foundationStrings.d.ts.map +1 -0
- package/dist/esm/foundation/foundationStrings.js +101 -0
- package/dist/esm/foundation/foundationStrings.js.map +1 -0
- package/dist/esm/foundation/index.d.ts +16 -0
- package/dist/esm/foundation/index.d.ts.map +1 -0
- package/dist/esm/foundation/index.js +16 -0
- package/dist/esm/foundation/index.js.map +1 -0
- package/dist/esm/gallery/widgets.js +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/themes/dark.d.ts.map +1 -1
- package/dist/esm/themes/dark.js +9 -1
- package/dist/esm/themes/dark.js.map +1 -1
- package/dist/esm/themes/light.d.ts.map +1 -1
- package/dist/esm/themes/light.js +10 -2
- package/dist/esm/themes/light.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/foundation/ActionButton.tsx +39 -0
- package/foundation/ComponentState.ts +53 -0
- package/foundation/EmptyState.tsx +22 -0
- package/foundation/Foundation.stories.tsx +30 -0
- package/foundation/FoundationIcon.tsx +49 -0
- package/foundation/FoundationStates.tsx +46 -0
- package/foundation/PermissionRule.ts +26 -0
- package/foundation/StatCard.tsx +44 -0
- package/foundation/StateFrame.tsx +126 -0
- package/foundation/StatusChip.tsx +51 -0
- package/foundation/TrendChip.tsx +78 -0
- package/foundation/formatting.ts +69 -0
- package/foundation/foundationComponentMetadata.ts +17 -0
- package/foundation/foundationDescriptors.ts +119 -0
- package/foundation/foundationSamples.ts +44 -0
- package/foundation/foundationStrings.ts +112 -0
- package/foundation/index.ts +18 -0
- package/index.ts +1 -0
- package/package.json +9 -8
- package/shell/layout.css +241 -0
- package/themes/dark.ts +8 -0
- package/themes/light.ts +9 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var ComponentState = require('./ComponentState.js');
|
|
5
|
+
var StateFrame = require('./StateFrame.js');
|
|
6
|
+
var TrendChip = require('./TrendChip.js');
|
|
7
|
+
var formatting = require('./formatting.js');
|
|
8
|
+
var foundationStrings = require('./foundationStrings.js');
|
|
9
|
+
var elementProperties = require('../shell/elementProperties.js');
|
|
10
|
+
|
|
11
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
12
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
13
|
+
/**
|
|
14
|
+
* The `statCard` component: one key figure with its label, its trend and what the trend is compared to - the unit of a dashboard's
|
|
15
|
+
* `kpis` slot.
|
|
16
|
+
*
|
|
17
|
+
* The value is a bound number, never embedded in the component (a figure is data, not design); it is formatted for the locale as
|
|
18
|
+
* a number, currency, percent or compact. With no value the card is empty, and it shows all five standard states
|
|
19
|
+
* independently of its neighbours, so a dashboard whose one query failed still shows the other cards.
|
|
20
|
+
*/ function StatCard({ element, interactions }) {
|
|
21
|
+
const value = element.properties.value;
|
|
22
|
+
const hasValue = typeof value === 'number';
|
|
23
|
+
const state = ComponentState.readComponentState(element, hasValue);
|
|
24
|
+
const locale = formatting.readLocale(element);
|
|
25
|
+
const label = elementProperties.readString(element, 'label');
|
|
26
|
+
const change = element.properties.change;
|
|
27
|
+
const currency = elementProperties.readOptionalString(element, 'currency');
|
|
28
|
+
return /*#__PURE__*/ jsxRuntime.jsx(StateFrame.FoundationFrame, {
|
|
29
|
+
element: element,
|
|
30
|
+
interactions: interactions,
|
|
31
|
+
name: "stat-card",
|
|
32
|
+
state: state,
|
|
33
|
+
skeleton: [
|
|
34
|
+
40,
|
|
35
|
+
70,
|
|
36
|
+
30
|
|
37
|
+
],
|
|
38
|
+
children: state !== ComponentState.ComponentState.Loading && /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
39
|
+
children: [
|
|
40
|
+
/*#__PURE__*/ jsxRuntime.jsx("h3", {
|
|
41
|
+
className: "foundation-stat-label",
|
|
42
|
+
children: label
|
|
43
|
+
}),
|
|
44
|
+
/*#__PURE__*/ jsxRuntime.jsx("p", {
|
|
45
|
+
className: "foundation-stat-value",
|
|
46
|
+
children: hasValue ? formatting.formatNumber(value, locale, formatting.readNumberFormat(element), currency, typeof element.properties.fractionDigits === 'number' ? element.properties.fractionDigits : undefined) : ''
|
|
47
|
+
}),
|
|
48
|
+
typeof change === 'number' && /*#__PURE__*/ jsxRuntime.jsx(TrendChip.TrendChipView, {
|
|
49
|
+
change: change,
|
|
50
|
+
locale: locale,
|
|
51
|
+
goodDirection: element.properties.goodDirection === 'down' ? 'down' : 'up',
|
|
52
|
+
comparison: elementProperties.readOptionalString(element, 'comparison'),
|
|
53
|
+
strings: foundationStrings.readFoundationStrings(element)
|
|
54
|
+
})
|
|
55
|
+
]
|
|
56
|
+
})
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.StatCard = StatCard;
|
|
61
|
+
//# sourceMappingURL=StatCard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatCard.js","sources":["../../../foundation/StatCard.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { RegisteredComponentProps } from '@cratis/scene.react';\nimport { ComponentState, readComponentState } from './ComponentState';\nimport { FoundationFrame } from './StateFrame';\nimport { TrendChipView } from './TrendChip';\nimport { formatNumber, readLocale, readNumberFormat } from './formatting';\nimport { readFoundationStrings } from './foundationStrings';\nimport { readOptionalString, readString } from '../shell/elementProperties';\n\n/**\n * The `statCard` component: one key figure with its label, its trend and what the trend is compared to - the unit of a dashboard's\n * `kpis` slot.\n *\n * The value is a bound number, never embedded in the component (a figure is data, not design); it is formatted for the locale as\n * a number, currency, percent or compact. With no value the card is empty, and it shows all five standard states\n * independently of its neighbours, so a dashboard whose one query failed still shows the other cards.\n */\nexport function StatCard({ element, interactions }: RegisteredComponentProps) {\n const value = element.properties.value;\n const hasValue = typeof value === 'number';\n const state = readComponentState(element, hasValue);\n const locale = readLocale(element);\n const label = readString(element, 'label');\n const change = element.properties.change;\n const currency = readOptionalString(element, 'currency');\n\n return (\n <FoundationFrame element={element} interactions={interactions}\n name='stat-card' state={state} skeleton={[40, 70, 30]}>\n {state !== ComponentState.Loading && (\n <>\n <h3 className='foundation-stat-label'>{label}</h3>\n <p className='foundation-stat-value'>{hasValue ? formatNumber(value, locale, readNumberFormat(element), currency, typeof element.properties.fractionDigits === 'number' ? element.properties.fractionDigits : undefined) : ''}</p>\n {typeof change === 'number' && (\n <TrendChipView change={change} locale={locale} goodDirection={element.properties.goodDirection === 'down' ? 'down' : 'up'}\n comparison={readOptionalString(element, 'comparison')} strings={readFoundationStrings(element)} />\n )}\n </>\n )}\n </FoundationFrame>\n );\n}\n"],"names":["StatCard","element","interactions","value","properties","hasValue","state","readComponentState","locale","readLocale","label","readString","change","currency","readOptionalString","_jsx","FoundationFrame","name","skeleton","ComponentState","Loading","_jsxs","_Fragment","h3","className","p","formatNumber","readNumberF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QG,UAAU,CAACwB,cAAc,KAAK,QAAA,GAAW3B,OAAAA,CAAQG,UAAU,CAACwB,cAAc,GAAGC,SAAAA,CAAAA,GAAa;;gBAC1N,OAAOjB,MAAAA,KAAW,0BACfG,cAAA,CAACe,uBAAAA,EAAAA;oBAAclB,MAAAA,EAAQA,MAAAA;oBAAQJ,MAAAA,EAAQA,MAAAA;AAAQuB,oBAAAA,aAAAA,EAAe9B,QAAQG,UAAU,CAAC2B,aAAa,KAAK,SAAS,MAAA,GAAS,IAAA;AACjHC,oBAAAA,UAAAA,EAAYlB,qCAAmBb,OAAAA,EAAS,YAAA,CAAA;AAAegC,oBAAAA,OAAAA,EAASC,uCAAAA,CAAsBjC,OAAAA;;;;;AAMlH;;"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var elementProperties = require('../shell/elementProperties.js');
|
|
5
|
+
var ActionButton = require('./ActionButton.js');
|
|
6
|
+
var ComponentState = require('./ComponentState.js');
|
|
7
|
+
var FoundationIcon = require('./FoundationIcon.js');
|
|
8
|
+
var foundationStrings = require('./foundationStrings.js');
|
|
9
|
+
var PermissionRule = require('./PermissionRule.js');
|
|
10
|
+
var formatting = require('./formatting.js');
|
|
11
|
+
|
|
12
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
13
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
14
|
+
/** The accessible name of a region, from the element's `label` property. */ function regionLabel(element) {
|
|
15
|
+
return elementProperties.readOptionalString(element, 'label') ?? elementProperties.readOptionalString(element, 'title');
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The root every foundation component renders, and the five standard states of spec Part B 1.4 in one place:
|
|
19
|
+
* a skeleton while loading (never a spinner alone), an explanation with the primary action when empty, a message with a
|
|
20
|
+
* retry on error, what is missing - and nothing of the data - when the user is not allowed, and the loaded part with a
|
|
21
|
+
* note naming what failed when only some regions did.
|
|
22
|
+
*
|
|
23
|
+
* The region carries an ARIA landmark role when it has a label, a `dir` is left to the document so right-to-left is
|
|
24
|
+
* inherited, and every piece of text comes from the strings table.
|
|
25
|
+
*/ function FoundationFrame({ element, interactions, name, state, skeleton = [
|
|
26
|
+
60,
|
|
27
|
+
100,
|
|
28
|
+
80
|
|
29
|
+
], children }) {
|
|
30
|
+
const strings = foundationStrings.readFoundationStrings(element);
|
|
31
|
+
const label = regionLabel(element);
|
|
32
|
+
const density = element.properties.density === 'compact' ? 'compact' : 'comfortable';
|
|
33
|
+
return /*#__PURE__*/ jsxRuntime.jsx("section", {
|
|
34
|
+
className: `foundation foundation-${name}`,
|
|
35
|
+
"data-scene-id": element.id,
|
|
36
|
+
"data-state": state,
|
|
37
|
+
"data-density": density,
|
|
38
|
+
lang: formatting.readLocale(element),
|
|
39
|
+
role: label ? 'region' : undefined,
|
|
40
|
+
"aria-label": label,
|
|
41
|
+
"aria-busy": state === ComponentState.ComponentState.Loading || undefined,
|
|
42
|
+
children: renderState(element, interactions, strings, state, skeleton, children)
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function renderState(element, interactions, strings, state, skeleton, children) {
|
|
46
|
+
switch(state){
|
|
47
|
+
case ComponentState.ComponentState.Loading:
|
|
48
|
+
return /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
49
|
+
className: "foundation-skeleton",
|
|
50
|
+
role: "status",
|
|
51
|
+
children: [
|
|
52
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
53
|
+
className: "foundation-visually-hidden",
|
|
54
|
+
children: strings.loading
|
|
55
|
+
}),
|
|
56
|
+
skeleton.map((width, index)=>/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
57
|
+
className: "foundation-skeleton-block",
|
|
58
|
+
style: {
|
|
59
|
+
width: `${width}%`
|
|
60
|
+
},
|
|
61
|
+
"aria-hidden": "true"
|
|
62
|
+
}, index))
|
|
63
|
+
]
|
|
64
|
+
});
|
|
65
|
+
case ComponentState.ComponentState.Empty:
|
|
66
|
+
return /*#__PURE__*/ jsxRuntime.jsx(EmptyStateView, {
|
|
67
|
+
element: element,
|
|
68
|
+
interactions: interactions,
|
|
69
|
+
strings: strings
|
|
70
|
+
});
|
|
71
|
+
case ComponentState.ComponentState.Error:
|
|
72
|
+
return /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
73
|
+
className: "foundation-message",
|
|
74
|
+
"data-tone": "danger",
|
|
75
|
+
role: "alert",
|
|
76
|
+
children: [
|
|
77
|
+
/*#__PURE__*/ jsxRuntime.jsx(FoundationIcon.FoundationIcon, {
|
|
78
|
+
name: "alert"
|
|
79
|
+
}),
|
|
80
|
+
/*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
81
|
+
className: "foundation-message-text",
|
|
82
|
+
children: [
|
|
83
|
+
/*#__PURE__*/ jsxRuntime.jsx("strong", {
|
|
84
|
+
children: strings.errorHeadline
|
|
85
|
+
}),
|
|
86
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
87
|
+
children: typeof element.properties.error === 'string' && element.properties.error.length > 0 ? element.properties.error : strings.errorHint
|
|
88
|
+
})
|
|
89
|
+
]
|
|
90
|
+
}),
|
|
91
|
+
/*#__PURE__*/ jsxRuntime.jsx(ActionButton.ActionButton, {
|
|
92
|
+
emphasis: "secondary",
|
|
93
|
+
disabledReason: strings.disabledNoPermission,
|
|
94
|
+
onClick: interactions?.onClick,
|
|
95
|
+
children: strings.retry
|
|
96
|
+
})
|
|
97
|
+
]
|
|
98
|
+
});
|
|
99
|
+
case ComponentState.ComponentState.NoPermission:
|
|
100
|
+
{
|
|
101
|
+
const subject = elementProperties.readOptionalString(element, 'permissionSubject') ?? strings.noPermissionSubject;
|
|
102
|
+
return /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
103
|
+
className: "foundation-message",
|
|
104
|
+
"data-tone": "neutral",
|
|
105
|
+
role: "status",
|
|
106
|
+
children: [
|
|
107
|
+
/*#__PURE__*/ jsxRuntime.jsx(FoundationIcon.FoundationIcon, {
|
|
108
|
+
name: "lock"
|
|
109
|
+
}),
|
|
110
|
+
/*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
111
|
+
className: "foundation-message-text",
|
|
112
|
+
children: [
|
|
113
|
+
/*#__PURE__*/ jsxRuntime.jsx("strong", {
|
|
114
|
+
children: strings.noPermissionHeadline
|
|
115
|
+
}),
|
|
116
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
117
|
+
children: foundationStrings.formatText(strings.noPermissionHint, {
|
|
118
|
+
subject
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
]
|
|
122
|
+
})
|
|
123
|
+
]
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
case ComponentState.ComponentState.Partial:
|
|
127
|
+
return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
128
|
+
children: [
|
|
129
|
+
/*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
130
|
+
className: "foundation-message",
|
|
131
|
+
"data-tone": "warning",
|
|
132
|
+
role: "status",
|
|
133
|
+
children: [
|
|
134
|
+
/*#__PURE__*/ jsxRuntime.jsx(FoundationIcon.FoundationIcon, {
|
|
135
|
+
name: "alert"
|
|
136
|
+
}),
|
|
137
|
+
/*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
138
|
+
className: "foundation-message-text",
|
|
139
|
+
children: [
|
|
140
|
+
/*#__PURE__*/ jsxRuntime.jsx("strong", {
|
|
141
|
+
children: strings.partialHeadline
|
|
142
|
+
}),
|
|
143
|
+
elementProperties.readStrings(element, 'failedRegions').length > 0 && /*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
144
|
+
children: foundationStrings.formatText(strings.partialHint, {
|
|
145
|
+
regions: elementProperties.readStrings(element, 'failedRegions').join(', ')
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
]
|
|
149
|
+
}),
|
|
150
|
+
/*#__PURE__*/ jsxRuntime.jsx(ActionButton.ActionButton, {
|
|
151
|
+
emphasis: "secondary",
|
|
152
|
+
disabledReason: strings.disabledNoPermission,
|
|
153
|
+
onClick: interactions?.onClick,
|
|
154
|
+
children: strings.retry
|
|
155
|
+
})
|
|
156
|
+
]
|
|
157
|
+
}),
|
|
158
|
+
children
|
|
159
|
+
]
|
|
160
|
+
});
|
|
161
|
+
default:
|
|
162
|
+
return /*#__PURE__*/ jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
163
|
+
children: children
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/** What an empty region says: an icon, a headline, a hint and the primary action, with the action's permission rule applied. */ function EmptyStateView({ element, interactions, strings }) {
|
|
168
|
+
const icon = elementProperties.readOptionalString(element, 'emptyIcon') ?? elementProperties.readOptionalString(element, 'icon');
|
|
169
|
+
const actionLabel = elementProperties.readOptionalString(element, 'emptyActionLabel') ?? elementProperties.readOptionalString(element, 'actionLabel');
|
|
170
|
+
return /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
171
|
+
className: "foundation-empty",
|
|
172
|
+
role: "status",
|
|
173
|
+
children: [
|
|
174
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
175
|
+
className: "foundation-empty-icon",
|
|
176
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(FoundationIcon.FoundationIcon, {
|
|
177
|
+
name: icon ?? 'inbox'
|
|
178
|
+
})
|
|
179
|
+
}),
|
|
180
|
+
/*#__PURE__*/ jsxRuntime.jsx("strong", {
|
|
181
|
+
className: "foundation-empty-headline",
|
|
182
|
+
children: elementProperties.readOptionalString(element, 'emptyHeadline') ?? elementProperties.readOptionalString(element, 'headline') ?? strings.emptyHeadline
|
|
183
|
+
}),
|
|
184
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
185
|
+
className: "foundation-empty-hint",
|
|
186
|
+
children: elementProperties.readOptionalString(element, 'emptyHint') ?? elementProperties.readOptionalString(element, 'hint') ?? strings.emptyHint
|
|
187
|
+
}),
|
|
188
|
+
actionLabel && /*#__PURE__*/ jsxRuntime.jsx(ActionButton.ActionButton, {
|
|
189
|
+
rule: PermissionRule.readPermissionRule(element, 'actionPermission'),
|
|
190
|
+
disabledReason: strings.disabledNoPermission,
|
|
191
|
+
onClick: interactions?.onClick,
|
|
192
|
+
children: actionLabel
|
|
193
|
+
})
|
|
194
|
+
]
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
exports.EmptyStateView = EmptyStateView;
|
|
199
|
+
exports.FoundationFrame = FoundationFrame;
|
|
200
|
+
//# sourceMappingURL=StateFrame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StateFrame.js","sources":["../../../foundation/StateFrame.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ReactNode } from 'react';\nimport { ExternalComponent } from '@cratis/scene.model';\nimport { RegisteredComponentProps } from '@cratis/scene.react';\nimport { readOptionalString, readStrings } from '../shell/elementProperties';\nimport { ActionButton } from './ActionButton';\nimport { ComponentState } from './ComponentState';\nimport { FoundationIcon, FoundationIconName } from './FoundationIcon';\nimport { FoundationStrings, formatText, readFoundationStrings } from './foundationStrings';\nimport { readPermissionRule } from './PermissionRule';\nimport { readLocale } from './formatting';\n\nexport interface FoundationFrameProps extends Pick<RegisteredComponentProps, 'element' | 'interactions'> {\n /** The component's own class, added after `foundation`. */\n name: string;\n\n /** The state the component is in; compute it with `readComponentState`. */\n state: ComponentState;\n\n /** The shape of the skeleton, as the width of each block in percent; the skeleton keeps the footprint of the content. */\n skeleton?: number[];\n\n /** What the component draws when it is ready or partial. */\n children?: ReactNode;\n}\n\n/** The accessible name of a region, from the element's `label` property. */\nfunction regionLabel(element: ExternalComponent): string | undefined {\n return readOptionalString(element, 'label') ?? readOptionalString(element, 'title');\n}\n\n/**\n * The root every foundation component renders, and the five standard states of spec Part B 1.4 in one place:\n * a skeleton while loading (never a spinner alone), an explanation with the primary action when empty, a message with a\n * retry on error, what is missing - and nothing of the data - when the user is not allowed, and the loaded part with a\n * note naming what failed when only some regions did.\n *\n * The region carries an ARIA landmark role when it has a label, a `dir` is left to the document so right-to-left is\n * inherited, and every piece of text comes from the strings table.\n */\nexport function FoundationFrame({ element, interactions, name, state, skeleton = [60, 100, 80], children }: FoundationFrameProps) {\n const strings = readFoundationStrings(element);\n const label = regionLabel(element);\n const density = element.properties.density === 'compact' ? 'compact' : 'comfortable';\n\n return (\n <section className={`foundation foundation-${name}`} data-scene-id={element.id} data-state={state} data-density={density}\n lang={readLocale(element)} role={label ? 'region' : undefined} aria-label={label} aria-busy={state === ComponentState.Loading || undefined}>\n {renderState(element, interactions, strings, state, skeleton, children)}\n </section>\n );\n}\n\nfunction renderState(element: ExternalComponent, interactions: RegisteredComponentProps['interactions'], strings: FoundationStrings, state: ComponentState, skeleton: number[], children: ReactNode) {\n switch (state) {\n case ComponentState.Loading:\n return (\n <div className='foundation-skeleton' role='status'>\n <span className='foundation-visually-hidden'>{strings.loading}</span>\n {skeleton.map((width, index) => <span key={index} className='foundation-skeleton-block' style={{ width: `${width}%` }} aria-hidden='true' />)}\n </div>\n );\n case ComponentState.Empty:\n return <EmptyStateView element={element} interactions={interactions} strings={strings} />;\n case ComponentState.Error:\n return (\n <div className='foundation-message' data-tone='danger' role='alert'>\n <FoundationIcon name='alert' />\n <div className='foundation-message-text'>\n <strong>{strings.errorHeadline}</strong>\n <span>{typeof element.properties.error === 'string' && element.properties.error.length > 0 ? element.properties.error : strings.errorHint}</span>\n </div>\n <ActionButton emphasis='secondary' disabledReason={strings.disabledNoPermission} onClick={interactions?.onClick}>{strings.retry}</ActionButton>\n </div>\n );\n case ComponentState.NoPermission: {\n const subject = readOptionalString(element, 'permissionSubject') ?? strings.noPermissionSubject;\n return (\n <div className='foundation-message' data-tone='neutral' role='status'>\n <FoundationIcon name='lock' />\n <div className='foundation-message-text'>\n <strong>{strings.noPermissionHeadline}</strong>\n <span>{formatText(strings.noPermissionHint, { subject })}</span>\n </div>\n </div>\n );\n }\n\n case ComponentState.Partial:\n return (\n <>\n <div className='foundation-message' data-tone='warning' role='status'>\n <FoundationIcon name='alert' />\n <div className='foundation-message-text'>\n <strong>{strings.partialHeadline}</strong>\n {readStrings(element, 'failedRegions').length > 0 && <span>{formatText(strings.partialHint, { regions: readStrings(element, 'failedRegions').join(', ') })}</span>}\n </div>\n <ActionButton emphasis='secondary' disabledReason={strings.disabledNoPermission} onClick={interactions?.onClick}>{strings.retry}</ActionButton>\n </div>\n {children}\n </>\n );\n default:\n return <>{children}</>;\n }\n}\n\n/** What an empty region says: an icon, a headline, a hint and the primary action, with the action's permission rule applied. */\nexport function EmptyStateView({ element, interactions, strings }: Pick<FoundationFrameProps, 'element' | 'interactions'> & { strings: FoundationStrings }) {\n const icon = (readOptionalString(element, 'emptyIcon') ?? readOptionalString(element, 'icon')) as FoundationIconName | undefined;\n const actionLabel = readOptionalString(element, 'emptyActionLabel') ?? readOptionalString(element, 'actionLabel');\n\n return (\n <div className='foundation-empty' role='status'>\n <span className='foundation-empty-icon'><FoundationIcon name={icon ?? 'inbox'} /></span>\n <strong className='foundation-empty-headline'>{readOptionalString(element, 'emptyHeadline') ?? readOptionalString(element, 'headline') ?? strings.emptyHeadline}</strong>\n <span className='foundation-empty-hint'>{readOptionalString(element, 'emptyHint') ?? readOptionalString(element, 'hint') ?? strings.emptyHint}</span>\n {actionLabel && (\n <ActionButton rule={readPermissionRule(element, 'actionPermission')} disabledReason={strings.disabledNoPermission} onClick={interactions?.onClick}>{actionLabel}</ActionButton>\n )}\n </div>\n );\n}\n\n"],"names":["regionLabel","element","readOptionalString","FoundationFrame","interactions","name","state","skeleton","children","strings","readFoundationStrings","label","density","properties","_jsx","section","className","data-scene-id","id","data-state","data-density","lang","readLocale","role","undefined","aria-label","aria-busy","ComponentState","Loading","renderState","_jsxs","div","span","loading","map","width","index","style","aria-hidden","Empty","EmptyStateView","Error","data-tone","FoundationIcon","strong","errorHeadline","error","length","errorHint","ActionButton","emphasis","disabledReason","disabledNoPermission","onClick","retry","NoPermission","subject","noPermissionSubject","noPermissionHeadline","formatText","noPermissionHint","Partial","_Fragment","partialHeadline","readStrings","partialHint","regions","join","icon","actionLabel","emptyHeadline","emptyHint","rule","readPermissionRule"],"mappings":";;;;;;;;;;;AAAA;AACA;AA2BA,6EACA,SAASA,WAAAA,CAAYC,OAA0B,EAAA;AAC3C,IAAA,OAAOC,oCAAAA,CAAmBD,OAAAA,EAAS,OAAA,CAAA,IAAYC,oCAAAA,CAAmBD,OAAAA,EAAS,OAAA,CAAA;AAC/E;AAEA;;;;;;;;AAQC,IACM,SAASE,eAAAA,CAAgB,EAAEF,OAAO,EAAEG,YAAY,EAAEC,IAAI,EAAEC,KAAK,EAAEC,QAAAA,GAAW;AAAC,IAAA,EAAA;AAAI,IAAA,GAAA;AAAK,IAAA;AAAG,CAAA,EAAEC,QAAQ,EAAwB,EAAA;AAC5H,IAAA,MAAMC,UAAUC,uCAAAA,CAAsBT,OAAAA,CAAAA;AACtC,IAAA,MAAMU,QAAQX,WAAAA,CAAYC,OAAAA,CAAAA;AAC1B,IAAA,MAAMW,UAAUX,OAAAA,CAAQY,UAAU,CAACD,OAAO,KAAK,YAAY,SAAA,GAAY,aAAA;AAEvE,IAAA,qBACIE,cAAA,CAACC,SAAAA,EAAAA;QAAQC,SAAAA,EAAW,CAAC,sBAAsB,EAAEX,IAAAA,CAAAA,CAAM;AAAEY,QAAAA,eAAAA,EAAehB,QAAQiB,EAAE;QAAEC,YAAAA,EAAYb,KAAAA;QAAOc,cAAAA,EAAcR,OAAAA;AAC7GS,QAAAA,IAAAA,EAAMC,qBAAAA,CAAWrB,OAAAA,CAAAA;AAAUsB,QAAAA,IAAAA,EAAMZ,QAAQ,QAAA,GAAWa,SAAAA;QAAWC,YAAAA,EAAYd,KAAAA;QAAOe,WAAAA,EAAWpB,KAAAA,KAA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
var foundationStrings = require('./foundationStrings.js');
|
|
5
|
+
var FoundationIcon = require('./FoundationIcon.js');
|
|
6
|
+
var elementProperties = require('../shell/elementProperties.js');
|
|
7
|
+
|
|
8
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
9
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
10
|
+
/** The semantic tone of a status. */ var StatusTone = /*#__PURE__*/ function(StatusTone) {
|
|
11
|
+
StatusTone["Success"] = "success";
|
|
12
|
+
StatusTone["Warning"] = "warning";
|
|
13
|
+
StatusTone["Danger"] = "danger";
|
|
14
|
+
StatusTone["Info"] = "info";
|
|
15
|
+
StatusTone["Neutral"] = "neutral";
|
|
16
|
+
return StatusTone;
|
|
17
|
+
}({});
|
|
18
|
+
/** The icon each tone gets, so a status is told by shape as well as color (WCAG 1.4.1). */ const statusToneIcons = {
|
|
19
|
+
["success"]: 'check',
|
|
20
|
+
["warning"]: 'alert',
|
|
21
|
+
["danger"]: 'close',
|
|
22
|
+
["info"]: 'info',
|
|
23
|
+
["neutral"]: 'circle'
|
|
24
|
+
};
|
|
25
|
+
/** Reads a tone, defaulting to Neutral. */ function readStatusTone(value) {
|
|
26
|
+
return Object.values(StatusTone).includes(value) ? value : "neutral";
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The `statusChip` component: a status as a semantic color, an icon and its text.
|
|
30
|
+
*
|
|
31
|
+
* The text is always shown - the status of a record is never only a colored dot - and the tone picks the icon and the color from
|
|
32
|
+
* the theme's status tokens. A status the application names ("Awaiting approval") is its own `status` text; `tone` maps it onto
|
|
33
|
+
* one of the five tones.
|
|
34
|
+
*/ function StatusChip({ element }) {
|
|
35
|
+
const tone = readStatusTone(element.properties.tone);
|
|
36
|
+
const strings = foundationStrings.readFoundationStrings(element);
|
|
37
|
+
const fallback = {
|
|
38
|
+
success: strings.statusSuccess,
|
|
39
|
+
warning: strings.statusWarning,
|
|
40
|
+
danger: strings.statusDanger,
|
|
41
|
+
info: strings.statusInfo,
|
|
42
|
+
neutral: strings.statusNeutral
|
|
43
|
+
}[tone];
|
|
44
|
+
const text = elementProperties.readString(element, 'status', elementProperties.readOptionalString(element, 'label') ?? fallback);
|
|
45
|
+
return /*#__PURE__*/ jsxRuntime.jsxs("span", {
|
|
46
|
+
className: "foundation foundation-chip foundation-status-chip",
|
|
47
|
+
"data-scene-id": element.id,
|
|
48
|
+
"data-tone": tone,
|
|
49
|
+
children: [
|
|
50
|
+
/*#__PURE__*/ jsxRuntime.jsx(FoundationIcon.FoundationIcon, {
|
|
51
|
+
name: statusToneIcons[tone]
|
|
52
|
+
}),
|
|
53
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
54
|
+
children: text
|
|
55
|
+
})
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.StatusChip = StatusChip;
|
|
61
|
+
exports.StatusTone = StatusTone;
|
|
62
|
+
exports.readStatusTone = readStatusTone;
|
|
63
|
+
exports.statusToneIcons = statusToneIcons;
|
|
64
|
+
//# sourceMappingURL=StatusChip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatusChip.js","sources":["../../../foundation/StatusChip.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { RegisteredComponentProps } from '@cratis/scene.react';\nimport { readFoundationStrings } from './foundationStrings';\nimport { FoundationIcon, FoundationIconName } from './FoundationIcon';\nimport { readOptionalString, readString } from '../shell/elementProperties';\n\n/** The semantic tone of a status. */\nexport enum StatusTone {\n Success = 'success',\n Warning = 'warning',\n Danger = 'danger',\n Info = 'info',\n Neutral = 'neutral',\n}\n\n/** The icon each tone gets, so a status is told by shape as well as color (WCAG 1.4.1). */\nexport const statusToneIcons: Record<StatusTone, FoundationIconName> = {\n [StatusTone.Success]: 'check',\n [StatusTone.Warning]: 'alert',\n [StatusTone.Danger]: 'close',\n [StatusTone.Info]: 'info',\n [StatusTone.Neutral]: 'circle',\n};\n\n/** Reads a tone, defaulting to Neutral. */\nexport function readStatusTone(value: unknown): StatusTone {\n return (Object.values(StatusTone) as string[]).includes(value as string) ? (value as StatusTone) : StatusTone.Neutral;\n}\n\n/**\n * The `statusChip` component: a status as a semantic color, an icon and its text.\n *\n * The text is always shown - the status of a record is never only a colored dot - and the tone picks the icon and the color from\n * the theme's status tokens. A status the application names (\"Awaiting approval\") is its own `status` text; `tone` maps it onto\n * one of the five tones.\n */\nexport function StatusChip({ element }: RegisteredComponentProps) {\n const tone = readStatusTone(element.properties.tone);\n const strings = readFoundationStrings(element);\n const fallback = { success: strings.statusSuccess, warning: strings.statusWarning, danger: strings.statusDanger, info: strings.statusInfo, neutral: strings.statusNeutral }[tone];\n const text = readString(element, 'status', readOptionalString(element, 'label') ?? fallback);\n\n return (\n <span className='foundation foundation-chip foundation-status-chip' data-scene-id={element.id} data-tone={tone}>\n <FoundationIcon name={statusToneIcons[tone]} />\n <span>{text}</span>\n </span>\n );\n}\n"],"names":["StatusTone","statusToneIcons","readStatusTone","value","Object","values","includes","StatusChip","element","tone","properties","strings","readFoundationStrings","fallback","success","statusSuccess","warning","statusWarning","danger","statusDanger","info","statusInfo","neutral","statusNeutral","text","readString","readOptionalString","_jsxs","span","className","data-scene-id","id","data-tone","_jsx","FoundationIcon","name"],"mappings":";;;;;;;AAAA;AACA;AAOA,sCACO,IAAKA,UAAAA,iBAAAA,SAAAA,UAAAA,EAAAA;;;;;;AAAAA,IAAAA,OAAAA,UAAAA;AAMX,CAAA,CAAA,EAAA;AAED,4FACO,MAAMC,eAAAA,GAA0D;AACnE,IAAA,CAAA,SAAA,GAAsB,OAAA;AACtB,IAAA,CAAA,SAAA,GAAsB,OAAA;AACtB,IAAA,CAAA,QAAA,GAAqB,OAAA;AACrB,IAAA,CAAA,MAAA,GAAmB,MAAA;AACnB,IAAA,CAAA,SAAA,GAAsB;AAC1B;AAEA,4CACO,SAASC,cAAAA,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require('./formatting.js');
|
|
6
|
+
var foundationStrings = require('./foundationStrings.js');
|
|
7
|
+
var elementProperties = require('../shell/elementProperties.js');
|
|
8
|
+
|
|
9
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
10
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
11
|
+
/** The direction a change moved in. */ function trendDirection(change) {
|
|
12
|
+
return change > 0 ? 'up' : change < 0 ? 'down' : 'flat';
|
|
13
|
+
}
|
|
14
|
+
/** Whether a movement is good for a measure, given which direction is the good one. */ function trendOutcome(direction, goodDirection) {
|
|
15
|
+
return direction === 'flat' ? 'neutral' : direction === goodDirection ? 'good' : 'bad';
|
|
16
|
+
}
|
|
17
|
+
/** The tone each outcome is drawn in. */ const tones = {
|
|
18
|
+
good: 'success',
|
|
19
|
+
bad: 'danger',
|
|
20
|
+
neutral: 'neutral'
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* A change, drawn as an arrow, the change and what it is compared to.
|
|
24
|
+
*
|
|
25
|
+
* Color says whether the movement is good, but never alone: the arrow gives direction and a visually hidden sentence
|
|
26
|
+
* says all of it ("up 12.5% compared to last month"), so the chip reads the same without color.
|
|
27
|
+
*/ function TrendChipView({ change, locale, goodDirection = 'up', comparison, format = formatting.NumberFormat.Percent, strings }) {
|
|
28
|
+
const direction = trendDirection(change);
|
|
29
|
+
const outcome = trendOutcome(direction, goodDirection);
|
|
30
|
+
const magnitude = formatting.formatNumber(Math.abs(change), locale, format);
|
|
31
|
+
const spoken = direction === 'flat' ? strings.trendFlat : foundationStrings.formatText(direction === 'up' ? strings.trendUp : strings.trendDown, {
|
|
32
|
+
value: magnitude
|
|
33
|
+
});
|
|
34
|
+
return /*#__PURE__*/ jsxRuntime.jsxs("span", {
|
|
35
|
+
className: "foundation-chip foundation-trend",
|
|
36
|
+
"data-tone": tones[outcome],
|
|
37
|
+
"data-direction": direction,
|
|
38
|
+
children: [
|
|
39
|
+
/*#__PURE__*/ jsxRuntime.jsx(FoundationIcon.FoundationIcon, {
|
|
40
|
+
name: direction === 'up' ? 'arrow-up' : direction === 'down' ? 'arrow-down' : 'minus'
|
|
41
|
+
}),
|
|
42
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
43
|
+
"aria-hidden": "true",
|
|
44
|
+
children: direction === 'flat' ? magnitude : magnitude
|
|
45
|
+
}),
|
|
46
|
+
/*#__PURE__*/ jsxRuntime.jsxs("span", {
|
|
47
|
+
className: "foundation-visually-hidden",
|
|
48
|
+
children: [
|
|
49
|
+
spoken,
|
|
50
|
+
comparison ? ` ${foundationStrings.formatText(strings.trendComparison, {
|
|
51
|
+
period: comparison
|
|
52
|
+
})}` : ''
|
|
53
|
+
]
|
|
54
|
+
}),
|
|
55
|
+
comparison && /*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
56
|
+
className: "foundation-trend-comparison",
|
|
57
|
+
"aria-hidden": "true",
|
|
58
|
+
children: foundationStrings.formatText(strings.trendComparison, {
|
|
59
|
+
period: comparison
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
]
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The `trendChip` component: a change with its direction, whether that is good, and what it is compared to.
|
|
67
|
+
*
|
|
68
|
+
* `change` is the movement as a number (a percentage by default), `goodDirection` says which way is good, and `comparison` names
|
|
69
|
+
* the period. Without a number the chip is empty, and then it draws nothing rather than an invented zero.
|
|
70
|
+
*/ function TrendChip({ element }) {
|
|
71
|
+
const change = element.properties.change;
|
|
72
|
+
if (typeof change !== 'number') return undefined;
|
|
73
|
+
return /*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
74
|
+
className: "foundation foundation-trend-chip",
|
|
75
|
+
"data-scene-id": element.id,
|
|
76
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(TrendChipView, {
|
|
77
|
+
change: change,
|
|
78
|
+
locale: formatting.readLocale(element),
|
|
79
|
+
goodDirection: element.properties.goodDirection === 'down' ? 'down' : 'up',
|
|
80
|
+
comparison: elementProperties.readOptionalString(element, 'comparison'),
|
|
81
|
+
strings: foundationStrings.readFoundationStrings(element),
|
|
82
|
+
...typeof element.properties.format === 'string' && Object.values(formatting.NumberFormat).includes(element.properties.format) ? {
|
|
83
|
+
format: element.properties.format
|
|
84
|
+
} : {}
|
|
85
|
+
})
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
exports.TrendChip = TrendChip;
|
|
90
|
+
exports.TrendChipView = TrendChipView;
|
|
91
|
+
exports.trendDirection = trendDirection;
|
|
92
|
+
exports.trendOutcome = trendOutcome;
|
|
93
|
+
//# sourceMappingURL=TrendChip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TrendChip.js","sources":["../../../foundation/TrendChip.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { RegisteredComponentProps } from '@cratis/scene.react';\nimport { FoundationIcon } from './FoundationIcon';\nimport { formatNumber, NumberFormat, readLocale } from './formatting';\nimport { formatText, readFoundationStrings } from './foundationStrings';\nimport { readOptionalString } from '../shell/elementProperties';\n\n/** The direction a measure moved. */\nexport type TrendDirection = 'up' | 'down' | 'flat';\n\n/** Whether a movement is good, bad or neither, which is independent of whether the number rose: falling response time is good. */\nexport type TrendOutcome = 'good' | 'bad' | 'neutral';\n\n/** The direction a change moved in. */\nexport function trendDirection(change: number): TrendDirection {\n return change > 0 ? 'up' : change < 0 ? 'down' : 'flat';\n}\n\n/** Whether a movement is good for a measure, given which direction is the good one. */\nexport function trendOutcome(direction: TrendDirection, goodDirection: 'up' | 'down'): TrendOutcome {\n return direction === 'flat' ? 'neutral' : direction === goodDirection ? 'good' : 'bad';\n}\n\n/** The tone each outcome is drawn in. */\nconst tones: Record<TrendOutcome, string> = { good: 'success', bad: 'danger', neutral: 'neutral' };\n\n/** The props of a trend chip drawn directly, as the stat card does. */\nexport interface TrendChipViewProps {\n change: number;\n locale: string;\n goodDirection?: 'up' | 'down';\n comparison?: string;\n format?: NumberFormat;\n strings: ReturnType<typeof readFoundationStrings>;\n}\n\n/**\n * A change, drawn as an arrow, the change and what it is compared to.\n *\n * Color says whether the movement is good, but never alone: the arrow gives direction and a visually hidden sentence\n * says all of it (\"up 12.5% compared to last month\"), so the chip reads the same without color.\n */\nexport function TrendChipView({ change, locale, goodDirection = 'up', comparison, format = NumberFormat.Percent, strings }: TrendChipViewProps) {\n const direction = trendDirection(change);\n const outcome = trendOutcome(direction, goodDirection);\n const magnitude = formatNumber(Math.abs(change), locale, format);\n const spoken = direction === 'flat' ? strings.trendFlat : formatText(direction === 'up' ? strings.trendUp : strings.trendDown, { value: magnitude });\n\n return (\n <span className='foundation-chip foundation-trend' data-tone={tones[outcome]} data-direction={direction}>\n <FoundationIcon name={direction === 'up' ? 'arrow-up' : direction === 'down' ? 'arrow-down' : 'minus'} />\n <span aria-hidden='true'>{direction === 'flat' ? magnitude : magnitude}</span>\n <span className='foundation-visually-hidden'>{spoken}{comparison ? ` ${formatText(strings.trendComparison, { period: comparison })}` : ''}</span>\n {comparison && <span className='foundation-trend-comparison' aria-hidden='true'>{formatText(strings.trendComparison, { period: comparison })}</span>}\n </span>\n );\n}\n\n/**\n * The `trendChip` component: a change with its direction, whether that is good, and what it is compared to.\n *\n * `change` is the movement as a number (a percentage by default), `goodDirection` says which way is good, and `comparison` names\n * the period. Without a number the chip is empty, and then it draws nothing rather than an invented zero.\n */\nexport function TrendChip({ element }: RegisteredComponentProps) {\n const change = element.properties.change;\n if (typeof change !== 'number') return undefined;\n\n return (\n <span className='foundation foundation-trend-chip' data-scene-id={element.id}>\n <TrendChipView change={change} locale={readLocale(element)} goodDirection={element.properties.goodDirection === 'down' ? 'down' : 'up'}\n comparison={readOptionalString(element, 'comparison')} strings={readFoundationStrings(element)}\n {...(typeof element.properties.format === 'string' && (Object.values(NumberFormat) as string[]).includes(element.properties.format) ? { format: element.properties.format as NumberFormat } : {})} />\n </span>\n );\n}\n"],"names":["trendDirection","change","trendOutcome","direction","goodDirection","tones","good","bad","neutral","TrendChipView","locale","comparison","format","NumberFormat","Percent","strings","outcome","magnitude","formatNumber","Math","abs","spoken","trendFlat","formatText","trendUp","trendDown","value","_jsxs","span","className","data-tone","data-direction","_jsx","FoundationIcon","name","aria-hidden","trendComparison","period","TrendChip","element","properties","undefined","data-scene-id","id","readLocale","readOptionalString","readFoundationStrings","Object","values","includes"],"mappings":";;;;;;;;AAAA;AACA;AAcA,wCACO,SAASA,cAAAA,CAAeC,MAAc,EAAA;AACzC,IAAA,OAAOA,MAAAA,GAAS,CAAA,GAAI,IAAA,GAAOA,MAAAA,GAAS,IAAI,MAAA,GAAS,MAAA;AACrD;AAEA,wFACO,SAASC,YAAAA,CAAaC,SAAyB,EAAEC,aAA4B,EAAA;AAChF,IAAA,OAAOD,SAAAA,KAAc,MAAA,GAAS,SAAA,GAAYA,SAAAA,KAAcC,gBAAgB,MAAA,GAAS,KAAA;AACrF;AAEA,0CACA,MAAMC,KAAAA,GAAsC;IAAEC,IAAAA,EAAM,SAAA;IAAWC,GAAAA,EAAK,QAAA;IAAUC,OAAAA,EAAS;AAAU,CAAA;AAYjG;;;;;AAKC,IACM,SAASC,aAAAA,CAAc,EAAER,MAAM,EAAES,MAAM,EAAEN,aAAAA,GAAgB,IAAI,EAAEO,UAAU,EAAEC,MAAAA,GAASC,wBAAaC,OAAO,EAAEC,OAAO,EAAsB,EAAA;AAC1I,IAAA,MAAMZ,YAAYH,cAAAA,CAAeC,MAAAA,CAAAA;IACjC,MAAMe,OAAAA,GAAUd,aAAaC,SAAAA,EAAWC,aAAAA,CAAAA;AACxC,IAAA,MAAMa,YAAYC,uBAAAA,CAAaC,IAAAA,CAAKC,GAAG,CAACnB,SAASS,MAAAA,EAAQE,MAAAA,CAAAA;AACzD,IAAA,MAAMS,MAAAA,GAASlB,SAAAA,KAAc,MAAA,GAASY,OAAAA,CAAQO,SAAS,GAAGC,4BAAAA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vC,IAAA,qBACIT,cAAA,CAACJ,MAAAA,EAAAA;QAAKC,SAAAA,EAAU,kCAAA;AAAmCa,QAAAA,eAAAA,EAAeH,QAAQI,EAAE;AACxE,QAAA,QAAA,gBAAAX,cAAA,CAACvB,aAAAA,EAAAA;YAAcR,MAAAA,EAAQA,MAAAA;AAAQS,YAAAA,MAAAA,EAAQkC,qBAAAA,CAAWL,OAAAA,CAAAA;AAAUnC,YAAAA,aAAAA,EAAemC,QAAQC,UAAU,CAACpC,aAAa,KAAK,SAAS,MAAA,GAAS,IAAA;AAC9HO,YAAAA,UAAAA,EAAYkC,qCAAmBN,OAAAA,EAAS,YAAA,CAAA;AAAexB,YAAAA,OAAAA,EAAS+B,uCAAAA,CAAsBP,OAAAA,CAAAA;AACrF,YAAA,GAAI,OAAOA,OAAAA,CAAQC,UAAU,CAAC5B,MAAM,KAAK,YAAY,MAACmC,CAAOC,MAAM,CAACnC,yBAA2BoC,QAAQ,CAACV,QAAQC,UAAU,CAAC5B,MAAM,CAAA,GAAI;gBAAEA,MAAAA,EAAQ2B,OAAAA,CAAQC,UAAU,CAAC5B;AAAuB,aAAA,GAAI;;;AAG9M;;;;;"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
4
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
5
|
+
/** How a number is presented. */ var NumberFormat = /*#__PURE__*/ function(NumberFormat) {
|
|
6
|
+
NumberFormat["Number"] = "number";
|
|
7
|
+
NumberFormat["Currency"] = "currency";
|
|
8
|
+
NumberFormat["Percent"] = "percent";
|
|
9
|
+
NumberFormat["Compact"] = "compact";
|
|
10
|
+
return NumberFormat;
|
|
11
|
+
}({});
|
|
12
|
+
/**
|
|
13
|
+
* The locale a component formats dates, numbers and currency in: the element's `locale`, else the document language, else the
|
|
14
|
+
* runtime's. Formatting never goes through a fixed locale, so the same screen reads correctly in every one.
|
|
15
|
+
*/ function readLocale(element) {
|
|
16
|
+
const supplied = element.properties.locale;
|
|
17
|
+
if (typeof supplied === 'string' && supplied.length > 0) return supplied;
|
|
18
|
+
if (typeof document !== 'undefined' && document.documentElement.lang) return document.documentElement.lang;
|
|
19
|
+
return typeof navigator !== 'undefined' && navigator.language ? navigator.language : 'en';
|
|
20
|
+
}
|
|
21
|
+
/** Whether the locale reads right to left, so a component can mirror what direction-sensitive CSS cannot. */ function isRightToLeft(locale) {
|
|
22
|
+
try {
|
|
23
|
+
const info = new Intl.Locale(locale);
|
|
24
|
+
const direction = info.getTextInfo?.().direction ?? info.textInfo?.direction;
|
|
25
|
+
return direction === 'rtl';
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Formats a number for a locale, as a plain number, currency, percent (the value is the percentage, 12.5 is 12.5%) or compact. */ function formatNumber(value, locale, format = "number", currency = 'USD', maximumFractionDigits) {
|
|
31
|
+
try {
|
|
32
|
+
switch(format){
|
|
33
|
+
case "currency":
|
|
34
|
+
return new Intl.NumberFormat(locale, {
|
|
35
|
+
style: 'currency',
|
|
36
|
+
currency,
|
|
37
|
+
...maximumFractionDigits === undefined ? {} : {
|
|
38
|
+
maximumFractionDigits
|
|
39
|
+
}
|
|
40
|
+
}).format(value);
|
|
41
|
+
case "percent":
|
|
42
|
+
return new Intl.NumberFormat(locale, {
|
|
43
|
+
style: 'percent',
|
|
44
|
+
maximumFractionDigits: maximumFractionDigits ?? 1
|
|
45
|
+
}).format(value / 100);
|
|
46
|
+
case "compact":
|
|
47
|
+
return new Intl.NumberFormat(locale, {
|
|
48
|
+
notation: 'compact',
|
|
49
|
+
maximumFractionDigits: maximumFractionDigits ?? 1
|
|
50
|
+
}).format(value);
|
|
51
|
+
default:
|
|
52
|
+
return new Intl.NumberFormat(locale, {
|
|
53
|
+
maximumFractionDigits: maximumFractionDigits ?? 2
|
|
54
|
+
}).format(value);
|
|
55
|
+
}
|
|
56
|
+
} catch {
|
|
57
|
+
return String(value);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Reads a number format name, defaulting to a plain number. */ function readNumberFormat(element, property = 'format') {
|
|
61
|
+
const value = element.properties[property];
|
|
62
|
+
return Object.values(NumberFormat).includes(value) ? value : "number";
|
|
63
|
+
}
|
|
64
|
+
/** Formats a date or an ISO 8601 date-time for a locale; a value that is not a date is returned as it was written. */ function formatDate(value, locale, withTime = false) {
|
|
65
|
+
const date = value instanceof Date ? value : typeof value === 'string' || typeof value === 'number' ? new Date(value) : undefined;
|
|
66
|
+
if (!date || Number.isNaN(date.getTime())) return typeof value === 'string' ? value : '';
|
|
67
|
+
try {
|
|
68
|
+
return new Intl.DateTimeFormat(locale, withTime ? {
|
|
69
|
+
dateStyle: 'medium',
|
|
70
|
+
timeStyle: 'short'
|
|
71
|
+
} : {
|
|
72
|
+
dateStyle: 'medium'
|
|
73
|
+
}).format(date);
|
|
74
|
+
} catch {
|
|
75
|
+
return date.toISOString();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
exports.NumberFormat = NumberFormat;
|
|
80
|
+
exports.formatDate = formatDate;
|
|
81
|
+
exports.formatNumber = formatNumber;
|
|
82
|
+
exports.isRightToLeft = isRightToLeft;
|
|
83
|
+
exports.readLocale = readLocale;
|
|
84
|
+
exports.readNumberFormat = readNumberFormat;
|
|
85
|
+
//# sourceMappingURL=formatting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatting.js","sources":["../../../foundation/formatting.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ExternalComponent } from '@cratis/scene.model';\n\n/** How a number is presented. */\nexport enum NumberFormat {\n Number = 'number',\n Currency = 'currency',\n Percent = 'percent',\n Compact = 'compact',\n}\n\n/**\n * The locale a component formats dates, numbers and currency in: the element's `locale`, else the document language, else the\n * runtime's. Formatting never goes through a fixed locale, so the same screen reads correctly in every one.\n */\nexport function readLocale(element: ExternalComponent): string {\n const supplied = element.properties.locale;\n if (typeof supplied === 'string' && supplied.length > 0) return supplied;\n if (typeof document !== 'undefined' && document.documentElement.lang) return document.documentElement.lang;\n return typeof navigator !== 'undefined' && navigator.language ? navigator.language : 'en';\n}\n\n/** Whether the locale reads right to left, so a component can mirror what direction-sensitive CSS cannot. */\nexport function isRightToLeft(locale: string): boolean {\n try {\n const info = new Intl.Locale(locale) as Intl.Locale & { getTextInfo?: () => { direction: string }; textInfo?: { direction: string } };\n const direction = info.getTextInfo?.().direction ?? info.textInfo?.direction;\n return direction === 'rtl';\n } catch {\n return false;\n }\n}\n\n/** Formats a number for a locale, as a plain number, currency, percent (the value is the percentage, 12.5 is 12.5%) or compact. */\nexport function formatNumber(value: number, locale: string, format: NumberFormat = NumberFormat.Number, currency = 'USD', maximumFractionDigits?: number): string {\n try {\n switch (format) {\n case NumberFormat.Currency:\n return new Intl.NumberFormat(locale, { style: 'currency', currency, ...(maximumFractionDigits === undefined ? {} : { maximumFractionDigits }) }).format(value);\n case NumberFormat.Percent:\n return new Intl.NumberFormat(locale, { style: 'percent', maximumFractionDigits: maximumFractionDigits ?? 1 }).format(value / 100);\n case NumberFormat.Compact:\n return new Intl.NumberFormat(locale, { notation: 'compact', maximumFractionDigits: maximumFractionDigits ?? 1 }).format(value);\n default:\n return new Intl.NumberFormat(locale, { maximumFractionDigits: maximumFractionDigits ?? 2 }).format(value);\n }\n } catch {\n return String(value);\n }\n}\n\n/** Reads a number format name, defaulting to a plain number. */\nexport function readNumberFormat(element: ExternalComponent, property = 'format'): NumberFormat {\n const value = element.properties[property];\n return (Object.values(NumberFormat) as string[]).includes(value as string) ? (value as NumberFormat) : NumberFormat.Number;\n}\n\n/** Formats a date or an ISO 8601 date-time for a locale; a value that is not a date is returned as it was written. */\nexport function formatDate(value: unknown, locale: string, withTime = false): string {\n const date = value instanceof Date ? value : typeof value === 'string' || typeof value === 'number' ? new Date(value) : undefined;\n if (!date || Number.isNaN(date.getTime())) return typeof value === 'string' ? value : '';\n try {\n return new Intl.DateTimeFormat(locale, withTime ? { dateStyle: 'medium', timeStyle: 'short' } : { dateStyle: 'medium' }).format(date);\n } catch {\n return date.toISOString();\n }\n}\n"],"names":["NumberFormat","readLocale","element","supplied","properties","locale","length","document","documentElement","lang","navigator","language","isRightToLeft","info","Intl","Locale","direction","getTextInfo","textInfo","formatNumber","value","format","currency","maximumFractionDigits","style","undefined","notation","String","readNumberFormat","property","Object","values","includes","formatDate","withTime","date","Date","Number","isNaN","getTime","DateTimeFormat","dateStyle","timeStyle","toISOString"],"mappings":";;AAAA;AACA;AAIA,kCACO,IAAKA,YAAAA,iBAAAA,SAAAA,YAAAA,EAAAA;;;;;AAAAA,IAAAA,OAAAA,YAAAA;AAKX,CAAA,CAAA,EAAA;AAED;;;IAIO,SAASC,UAAAA,CAAWC,OAA0B,EAAA;AACjD,IAAA,MAAMC,QAAAA,GAAWD,OAAAA,CAAQE,UAAU,CAACC,MAAM;AAC1C,IAAA,IAAI,OAAOF,QAAAA,KAAa,QAAA,IAAYA,SAASG,MAAM,GAAG,GAAG,OAAOH,QAAAA;AAChE,IAAA,IAAI,OAAOI,QAAAA,KAAa,WAAA,IAAeA,QAAAA,CAASC,eAAe,CAACC,IAAI,EAAE,OAAOF,QAAAA,CAASC,eAAe,CAACC,IAAI;IAC1G,OAAO,OAAOC,cAAc,WAAA,IAAeA,SAAAA,CAAUC,QAAQ,GAAGD,SAAAA,CAAUC,QAAQ,GAAG,IAAA;AACzF;AAEA,8GACO,SAASC,aAAAA,CAAcP,MAAc,EAAA;IACxC,IAAI;AACA,QAAA,MAAMQ,IAAAA,GAAO,IAAIC,IAAAA,CAAKC,MAAM,CAACV,MAAAA,CAAAA;AAC7B,QAAA,MAAMW,YAAYH,IAAAA,CAAKI,WAAW,KAAKD,SAAAA,IAAaH,IAAAA,CAAKK,QAAQ,EAAEF,SAAAA;AACnE,QAAA,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