pne-ui 4.8.0 → 5.0.0-rc.2
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/README.md +103 -17
- package/cjs/brandRamp.d.ts +10 -0
- package/cjs/brandRamp.js +51 -0
- package/cjs/brandRamp.js.map +1 -0
- package/cjs/buttonPalette.d.ts +38 -0
- package/cjs/buttonPalette.js +150 -0
- package/cjs/buttonPalette.js.map +1 -0
- package/cjs/checkboxPalette.d.ts +21 -0
- package/cjs/checkboxPalette.js +66 -0
- package/cjs/checkboxPalette.js.map +1 -0
- package/cjs/color.d.ts +10 -0
- package/cjs/color.js +65 -0
- package/cjs/color.js.map +1 -0
- package/cjs/component/PneButton.d.ts +17 -0
- package/cjs/component/PneButton.js +84 -182
- package/cjs/component/PneButton.js.map +1 -1
- package/cjs/component/PneCheckbox.d.ts +3 -0
- package/cjs/component/PneCheckbox.js +101 -3
- package/cjs/component/PneCheckbox.js.map +1 -1
- package/cjs/component/PneField.js +36 -16
- package/cjs/component/PneField.js.map +1 -1
- package/cjs/component/PneSwitch.d.ts +2 -0
- package/cjs/component/PneSwitch.js +82 -158
- package/cjs/component/PneSwitch.js.map +1 -1
- package/cjs/component/PneTextField.d.ts +14 -2
- package/cjs/component/PneTextField.js +20 -3
- package/cjs/component/PneTextField.js.map +1 -1
- package/cjs/component/dropdown/PneAsyncAutocomplete.js +8 -3
- package/cjs/component/dropdown/PneAsyncAutocomplete.js.map +1 -1
- package/cjs/component/dropdown/PneAutocomplete.d.ts +2 -0
- package/cjs/component/dropdown/PneAutocomplete.js +5 -3
- package/cjs/component/dropdown/PneAutocomplete.js.map +1 -1
- package/cjs/component/dropdown/PneAutocompleteShared.d.ts +11 -1
- package/cjs/component/dropdown/PneAutocompleteShared.js +45 -1
- package/cjs/component/dropdown/PneAutocompleteShared.js.map +1 -1
- package/cjs/component/dropdown/PneSelect.d.ts +2 -0
- package/cjs/component/dropdown/PneSelect.js +13 -5
- package/cjs/component/dropdown/PneSelect.js.map +1 -1
- package/cjs/component/dropdown/dropdownLook.d.ts +42 -0
- package/cjs/component/dropdown/dropdownLook.js +239 -0
- package/cjs/component/dropdown/dropdownLook.js.map +1 -0
- package/cjs/component/fieldLook.d.ts +8 -0
- package/cjs/component/fieldLook.js +71 -0
- package/cjs/component/fieldLook.js.map +1 -0
- package/cjs/component/non-abstract-entity-selector/styled.d.ts +1 -1
- package/cjs/component/search-ui/filters/component/select/style.js +4 -0
- package/cjs/component/search-ui/filters/component/select/style.js.map +1 -1
- package/cjs/component/search-ui/filters/styled.js +4 -1
- package/cjs/component/search-ui/filters/styled.js.map +1 -1
- package/cjs/component/table/PneTablePagination.d.ts +1 -1
- package/cjs/component/table/PneTableRow.d.ts +1 -1
- package/cjs/createTheme.d.ts +27 -21
- package/cjs/createTheme.js +73 -103
- package/cjs/createTheme.js.map +1 -1
- package/cjs/dropdownPalette.d.ts +44 -0
- package/cjs/dropdownPalette.js +53 -0
- package/cjs/dropdownPalette.js.map +1 -0
- package/cjs/exports/inputs.d.ts +1 -1
- package/cjs/exports/theme.d.ts +8 -1
- package/cjs/exports/theme.js +18 -1
- package/cjs/exports/theme.js.map +1 -1
- package/cjs/fieldPalette.d.ts +30 -0
- package/cjs/fieldPalette.js +71 -0
- package/cjs/fieldPalette.js.map +1 -0
- package/cjs/switchPalette.d.ts +26 -0
- package/cjs/switchPalette.js +60 -0
- package/cjs/switchPalette.js.map +1 -0
- package/cjs/themeColors.d.ts +54 -0
- package/cjs/themeColors.js +73 -0
- package/cjs/themeColors.js.map +1 -0
- package/esm/brandRamp.d.ts +10 -0
- package/esm/brandRamp.js +47 -0
- package/esm/brandRamp.js.map +1 -0
- package/esm/buttonPalette.d.ts +38 -0
- package/esm/buttonPalette.js +139 -0
- package/esm/buttonPalette.js.map +1 -0
- package/esm/checkboxPalette.d.ts +21 -0
- package/esm/checkboxPalette.js +62 -0
- package/esm/checkboxPalette.js.map +1 -0
- package/esm/color.d.ts +10 -0
- package/esm/color.js +56 -0
- package/esm/color.js.map +1 -0
- package/esm/component/PneButton.d.ts +17 -0
- package/esm/component/PneButton.js +84 -183
- package/esm/component/PneButton.js.map +1 -1
- package/esm/component/PneCheckbox.d.ts +3 -0
- package/esm/component/PneCheckbox.js +101 -3
- package/esm/component/PneCheckbox.js.map +1 -1
- package/esm/component/PneField.js +36 -16
- package/esm/component/PneField.js.map +1 -1
- package/esm/component/PneSwitch.d.ts +2 -0
- package/esm/component/PneSwitch.js +83 -159
- package/esm/component/PneSwitch.js.map +1 -1
- package/esm/component/PneTextField.d.ts +14 -2
- package/esm/component/PneTextField.js +20 -3
- package/esm/component/PneTextField.js.map +1 -1
- package/esm/component/dropdown/PneAsyncAutocomplete.js +9 -4
- package/esm/component/dropdown/PneAsyncAutocomplete.js.map +1 -1
- package/esm/component/dropdown/PneAutocomplete.d.ts +2 -0
- package/esm/component/dropdown/PneAutocomplete.js +6 -4
- package/esm/component/dropdown/PneAutocomplete.js.map +1 -1
- package/esm/component/dropdown/PneAutocompleteShared.d.ts +11 -1
- package/esm/component/dropdown/PneAutocompleteShared.js +42 -0
- package/esm/component/dropdown/PneAutocompleteShared.js.map +1 -1
- package/esm/component/dropdown/PneSelect.d.ts +2 -0
- package/esm/component/dropdown/PneSelect.js +13 -5
- package/esm/component/dropdown/PneSelect.js.map +1 -1
- package/esm/component/dropdown/dropdownLook.d.ts +42 -0
- package/esm/component/dropdown/dropdownLook.js +229 -0
- package/esm/component/dropdown/dropdownLook.js.map +1 -0
- package/esm/component/fieldLook.d.ts +8 -0
- package/esm/component/fieldLook.js +67 -0
- package/esm/component/fieldLook.js.map +1 -0
- package/esm/component/non-abstract-entity-selector/styled.d.ts +1 -1
- package/esm/component/search-ui/filters/component/select/style.js +4 -0
- package/esm/component/search-ui/filters/component/select/style.js.map +1 -1
- package/esm/component/search-ui/filters/styled.js +4 -1
- package/esm/component/search-ui/filters/styled.js.map +1 -1
- package/esm/component/table/PneTablePagination.d.ts +1 -1
- package/esm/component/table/PneTableRow.d.ts +1 -1
- package/esm/createTheme.d.ts +27 -21
- package/esm/createTheme.js +26 -58
- package/esm/createTheme.js.map +1 -1
- package/esm/dropdownPalette.d.ts +44 -0
- package/esm/dropdownPalette.js +49 -0
- package/esm/dropdownPalette.js.map +1 -0
- package/esm/exports/inputs.d.ts +1 -1
- package/esm/exports/theme.d.ts +8 -1
- package/esm/exports/theme.js +8 -1
- package/esm/exports/theme.js.map +1 -1
- package/esm/fieldPalette.d.ts +30 -0
- package/esm/fieldPalette.js +67 -0
- package/esm/fieldPalette.js.map +1 -0
- package/esm/switchPalette.d.ts +26 -0
- package/esm/switchPalette.js +56 -0
- package/esm/switchPalette.js.map +1 -0
- package/esm/themeColors.d.ts +54 -0
- package/esm/themeColors.js +70 -0
- package/esm/themeColors.js.map +1 -0
- package/package.json +7 -7
package/cjs/color.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hslToHex = exports.hexToHsl = exports.mixHex = exports.rgbToHex = exports.hexToRgb = exports.normalizeHexColor = exports.MISSING_COLOR = void 0;
|
|
4
|
+
/** Shown in place of a skin colour that is missing or not a hex colour, so the gap is visible. */
|
|
5
|
+
exports.MISSING_COLOR = '#FF00DC';
|
|
6
|
+
const normalizeHexColor = (value) => {
|
|
7
|
+
const color = value?.trim();
|
|
8
|
+
if (!color)
|
|
9
|
+
return exports.MISSING_COLOR;
|
|
10
|
+
const shortMatch = /^#([0-9a-f]{3})$/i.exec(color);
|
|
11
|
+
if (shortMatch) {
|
|
12
|
+
return `#${shortMatch[1].split('').map(part => `${part}${part}`).join('')}`.toUpperCase();
|
|
13
|
+
}
|
|
14
|
+
return /^#[0-9a-f]{6}$/i.test(color) ? color.toUpperCase() : exports.MISSING_COLOR;
|
|
15
|
+
};
|
|
16
|
+
exports.normalizeHexColor = normalizeHexColor;
|
|
17
|
+
const hexToRgb = (color) => {
|
|
18
|
+
const value = Number.parseInt(color.slice(1), 16);
|
|
19
|
+
return [value >> 16, (value >> 8) & 255, value & 255];
|
|
20
|
+
};
|
|
21
|
+
exports.hexToRgb = hexToRgb;
|
|
22
|
+
const rgbToHex = (red, green, blue) => `#${[red, green, blue]
|
|
23
|
+
.map(channel => Math.max(0, Math.min(255, Math.round(channel))).toString(16).padStart(2, '0'))
|
|
24
|
+
.join('')}`.toUpperCase();
|
|
25
|
+
exports.rgbToHex = rgbToHex;
|
|
26
|
+
/** Moves `color` towards `target` by `amount` (0…1) in sRGB. */
|
|
27
|
+
const mixHex = (color, target, amount) => {
|
|
28
|
+
const sourceChannels = (0, exports.hexToRgb)(color);
|
|
29
|
+
const targetChannels = (0, exports.hexToRgb)(target);
|
|
30
|
+
return (0, exports.rgbToHex)(sourceChannels[0] + (targetChannels[0] - sourceChannels[0]) * amount, sourceChannels[1] + (targetChannels[1] - sourceChannels[1]) * amount, sourceChannels[2] + (targetChannels[2] - sourceChannels[2]) * amount);
|
|
31
|
+
};
|
|
32
|
+
exports.mixHex = mixHex;
|
|
33
|
+
/** Hue in degrees, saturation and lightness in 0…1. */
|
|
34
|
+
const hexToHsl = (color) => {
|
|
35
|
+
const [red, green, blue] = (0, exports.hexToRgb)(color).map(channel => channel / 255);
|
|
36
|
+
const max = Math.max(red, green, blue);
|
|
37
|
+
const min = Math.min(red, green, blue);
|
|
38
|
+
const lightness = (max + min) / 2;
|
|
39
|
+
if (max === min)
|
|
40
|
+
return [0, 0, lightness];
|
|
41
|
+
const delta = max - min;
|
|
42
|
+
const saturation = delta / (1 - Math.abs(2 * lightness - 1));
|
|
43
|
+
const hue = max === red
|
|
44
|
+
? 60 * (((green - blue) / delta + 6) % 6)
|
|
45
|
+
: max === green
|
|
46
|
+
? 60 * ((blue - red) / delta + 2)
|
|
47
|
+
: 60 * ((red - green) / delta + 4);
|
|
48
|
+
return [hue, saturation, lightness];
|
|
49
|
+
};
|
|
50
|
+
exports.hexToHsl = hexToHsl;
|
|
51
|
+
const hslToHex = (hue, saturation, lightness) => {
|
|
52
|
+
const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
|
|
53
|
+
const sector = hue / 60;
|
|
54
|
+
const second = chroma * (1 - Math.abs(sector % 2 - 1));
|
|
55
|
+
const [red, green, blue] = sector < 1 ? [chroma, second, 0]
|
|
56
|
+
: sector < 2 ? [second, chroma, 0]
|
|
57
|
+
: sector < 3 ? [0, chroma, second]
|
|
58
|
+
: sector < 4 ? [0, second, chroma]
|
|
59
|
+
: sector < 5 ? [second, 0, chroma]
|
|
60
|
+
: [chroma, 0, second];
|
|
61
|
+
const offset = lightness - chroma / 2;
|
|
62
|
+
return (0, exports.rgbToHex)((red + offset) * 255, (green + offset) * 255, (blue + offset) * 255);
|
|
63
|
+
};
|
|
64
|
+
exports.hslToHex = hslToHex;
|
|
65
|
+
//# sourceMappingURL=color.js.map
|
package/cjs/color.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.js","sourceRoot":"","sources":["../src/color.ts"],"names":[],"mappings":";;;AAAA,kGAAkG;AACrF,QAAA,aAAa,GAAG,SAAS,CAAA;AAE/B,MAAM,iBAAiB,GAAG,CAAC,KAAyB,EAAU,EAAE;IACnE,MAAM,KAAK,GAAG,KAAK,EAAE,IAAI,EAAE,CAAA;IAC3B,IAAI,CAAC,KAAK;QAAE,OAAO,qBAAa,CAAA;IAEhC,MAAM,UAAU,GAAG,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAClD,IAAI,UAAU,EAAE,CAAC;QACb,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,CAAA;IAC7F,CAAC;IAED,OAAO,iBAAiB,CAAC,IAAI,CAAC,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MAAM,CAAC;wBAC9B,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAA;IACzC,MAAM,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,CAAC,CAAA;IACrC,OAAO,IAAA,gBAAQ,EAAC,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,GAAG,EAAE,CAAC,KAAK,GAAG,MAAM,CAAC,GAAG,GAAG,EAAE,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,GAAG,CAAC,CAAA;AACxF,CAAC,CAAA;AAZY,QAAA,QAAQ,YAYpB"}
|
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
import type { ButtonTypeMap } from '@mui/material/Button';
|
|
2
2
|
import type { OverridableComponent, OverrideProps } from '@mui/material/OverridableComponent';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
+
/**
|
|
5
|
+
* The PNE UI action button (UI Kit Button: Variant × Size × State). `contained` is the single
|
|
6
|
+
* main action on a page, `outlined` and `text` are secondary, `error` is for removals,
|
|
7
|
+
* `warning` is a non-destructive caution, and the four soft styles (`neutral`, `neutralText`,
|
|
8
|
+
* `primaryLight`, `white`) have a brand label and no fill at rest, for tables and toolbars.
|
|
9
|
+
*/
|
|
4
10
|
export type PneButtonStyle = 'contained' | 'outlined' | 'error' | 'text' | 'neutral' | 'neutralText' | 'primaryLight' | 'warning' | 'white';
|
|
11
|
+
/** small 24px (tables, groups) · medium 32px (forms) · large 40px (page primary). */
|
|
5
12
|
export type PneButtonSize = 'small' | 'medium' | 'large';
|
|
13
|
+
/** A state pinned for specimens through `data-pne-state`; product code never sets it. */
|
|
14
|
+
export type PneButtonSpecimenState = 'hover' | 'pressed' | 'focus';
|
|
6
15
|
type PneButtonOwnProps = {
|
|
7
16
|
/** Canonical PNE appearance preset. */
|
|
8
17
|
pneStyle?: PneButtonStyle;
|
|
9
18
|
/** PNE buttons intentionally support only the three design-system sizes. */
|
|
10
19
|
size?: PneButtonSize;
|
|
20
|
+
/**
|
|
21
|
+
* A request is running: a spinner takes the start icon slot, the end icon hides, clicks are
|
|
22
|
+
* blocked and the resting colours stay. Give such a button a start icon, so its width does
|
|
23
|
+
* not change.
|
|
24
|
+
*/
|
|
25
|
+
loading?: boolean;
|
|
11
26
|
/** Use `pneStyle`; raw MUI colors are not part of the PneButton contract. */
|
|
12
27
|
color?: never;
|
|
13
28
|
/** Use `pneStyle`; raw MUI variants are not part of the PneButton contract. */
|
|
14
29
|
variant?: never;
|
|
30
|
+
'data-pne-state'?: PneButtonSpecimenState;
|
|
15
31
|
};
|
|
16
32
|
type PneButtonTypeMap<AdditionalProps = {}, RootComponent extends React.ElementType = 'button'> = {
|
|
17
33
|
props: Omit<ButtonTypeMap<PneButtonOwnProps & AdditionalProps, RootComponent>['props'], 'href'>;
|
|
@@ -23,5 +39,6 @@ export type PneButtonProps<RootComponent extends React.ElementType = 'button', A
|
|
|
23
39
|
type PneButtonComponent = ((props: {
|
|
24
40
|
href: string;
|
|
25
41
|
} & OverrideProps<PneButtonTypeMap, 'a'>) => React.JSX.Element) & OverridableComponent<PneButtonTypeMap>;
|
|
42
|
+
export declare const PNE_BUTTON_FONT_FAMILY = "\"Roboto\", \"Helvetica Neue\", Arial, sans-serif";
|
|
26
43
|
declare const PneButton: PneButtonComponent;
|
|
27
44
|
export default PneButton;
|
|
@@ -1,221 +1,123 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PNE_BUTTON_FONT_FAMILY = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const material_1 = require("@mui/material");
|
|
5
|
-
const styles_1 = require("@mui/material/styles");
|
|
6
6
|
const React = tslib_1.__importStar(require("react"));
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
contained:
|
|
11
|
-
outlined:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
white:
|
|
7
|
+
const createTheme_1 = require("../createTheme");
|
|
8
|
+
exports.PNE_BUTTON_FONT_FAMILY = '"Roboto", "Helvetica Neue", Arial, sans-serif';
|
|
9
|
+
const BUTTON_VARIANT = {
|
|
10
|
+
contained: 'primary',
|
|
11
|
+
outlined: 'outline',
|
|
12
|
+
text: 'text',
|
|
13
|
+
error: 'destructive',
|
|
14
|
+
warning: 'warning',
|
|
15
|
+
neutral: 'soft',
|
|
16
|
+
neutralText: 'soft',
|
|
17
|
+
primaryLight: 'soft',
|
|
18
|
+
white: 'soft',
|
|
19
19
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
iconNearPadding: 12,
|
|
26
|
-
iconFarPadding: 16,
|
|
27
|
-
iconOnlyPadding: 6,
|
|
28
|
-
gap: 4,
|
|
29
|
-
},
|
|
30
|
-
medium: {
|
|
31
|
-
height: 32,
|
|
32
|
-
verticalPadding: 6,
|
|
33
|
-
horizontalPadding: 20,
|
|
34
|
-
iconNearPadding: 16,
|
|
35
|
-
iconFarPadding: 20,
|
|
36
|
-
iconOnlyPadding: 8,
|
|
37
|
-
gap: 8,
|
|
38
|
-
},
|
|
39
|
-
large: {
|
|
40
|
-
height: 40,
|
|
41
|
-
verticalPadding: 10,
|
|
42
|
-
horizontalPadding: 20,
|
|
43
|
-
iconNearPadding: 16,
|
|
44
|
-
iconFarPadding: 20,
|
|
45
|
-
iconOnlyPadding: 10,
|
|
46
|
-
gap: 8,
|
|
47
|
-
},
|
|
20
|
+
// UI Kit sizes: control height, padding, Roboto Medium label, icon glyph.
|
|
21
|
+
const BUTTON_SIZE = {
|
|
22
|
+
small: { height: 24, paddingBlock: 4, paddingInline: 8, fontSize: 12, lineHeight: 16, icon: 14 },
|
|
23
|
+
medium: { height: 32, paddingBlock: 6, paddingInline: 12, fontSize: 13, lineHeight: 18, icon: 16 },
|
|
24
|
+
large: { height: 40, paddingBlock: 10, paddingInline: 16, fontSize: 14, lineHeight: 20, icon: 18 },
|
|
48
25
|
};
|
|
49
|
-
const
|
|
50
|
-
|
|
26
|
+
const BUTTON_ICON_GAP = 4;
|
|
27
|
+
const isPneButtonSize = (size) => size === 'small' || size === 'medium' || size === 'large';
|
|
28
|
+
const resolveVariant = (pneStyle) => {
|
|
29
|
+
if (pneStyle === undefined)
|
|
30
|
+
return 'primary';
|
|
31
|
+
const variant = BUTTON_VARIANT[pneStyle];
|
|
32
|
+
if (variant !== undefined)
|
|
33
|
+
return variant;
|
|
34
|
+
console.warn(`Unknown pneStyle: ${String(pneStyle)}`);
|
|
35
|
+
return 'primary';
|
|
51
36
|
};
|
|
52
37
|
// https://mui.com/material-ui/guides/typescript/#complications-with-the-component-prop
|
|
53
38
|
const PneButtonImplementation = (props) => {
|
|
54
|
-
const { sx, children, variant, color, size = 'large', pneStyle, startIcon, endIcon, ...rest } = props;
|
|
39
|
+
const { sx, children, variant, color, size = 'large', pneStyle, loading = false, startIcon, endIcon, onClick, ...rest } = props;
|
|
55
40
|
const resolvedSize = isPneButtonSize(size) ? size : 'large';
|
|
56
41
|
if (variant !== undefined || color !== undefined) {
|
|
57
42
|
console.warn('PneButton ignores variant/color; use the canonical pneStyle prop');
|
|
58
43
|
}
|
|
59
|
-
const
|
|
60
|
-
const hasStartIcon = Boolean(startIcon);
|
|
61
|
-
const hasEndIcon = Boolean(endIcon);
|
|
44
|
+
const resolvedVariant = resolveVariant(pneStyle);
|
|
62
45
|
const hasChildren = React.Children.count(children) > 0;
|
|
63
|
-
const iconOnly = !hasChildren && (
|
|
46
|
+
const iconOnly = !hasChildren && Boolean(startIcon || endIcon);
|
|
47
|
+
const spinner = React.createElement(material_1.CircularProgress, { color: 'inherit', size: BUTTON_SIZE[resolvedSize].icon, thickness: 5 });
|
|
48
|
+
const handleClick = (event) => {
|
|
49
|
+
if (loading) {
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
onClick?.(event);
|
|
54
|
+
};
|
|
64
55
|
const _sx = [
|
|
65
|
-
createButtonSx({
|
|
66
|
-
|
|
67
|
-
hasEndIcon,
|
|
68
|
-
hasStartIcon,
|
|
69
|
-
iconOnly,
|
|
70
|
-
size: resolvedSize,
|
|
71
|
-
variant: resolvedStyle.variant,
|
|
72
|
-
}),
|
|
73
|
-
...(Array.isArray(sx) ? sx : [sx])
|
|
56
|
+
createButtonSx({ iconOnly, size: resolvedSize, variant: resolvedVariant }),
|
|
57
|
+
...(Array.isArray(sx) ? sx : [sx]),
|
|
74
58
|
];
|
|
75
|
-
return React.createElement(material_1.Button, { sx: _sx, variant:
|
|
76
|
-
};
|
|
77
|
-
const resolveButtonStyle = (pneStyle) => {
|
|
78
|
-
if (pneStyle === undefined) {
|
|
79
|
-
return buttonStyleConfig.contained;
|
|
80
|
-
}
|
|
81
|
-
const resolvedStyle = buttonStyleConfig[pneStyle];
|
|
82
|
-
if (resolvedStyle !== undefined) {
|
|
83
|
-
return resolvedStyle;
|
|
84
|
-
}
|
|
85
|
-
console.warn(`Unknown pneStyle: ${String(pneStyle)}`);
|
|
86
|
-
return buttonStyleConfig.contained;
|
|
59
|
+
return React.createElement(material_1.Button, { sx: _sx, variant: 'text', size: resolvedSize, disableElevation: true, startIcon: loading ? spinner : startIcon, endIcon: loading ? undefined : endIcon, "aria-busy": loading || undefined, "data-pne-variant": resolvedVariant, "data-pne-size": resolvedSize, "data-pne-loading": loading || undefined, onClick: handleClick, ...rest }, children);
|
|
87
60
|
};
|
|
88
61
|
const PneButton = PneButtonImplementation;
|
|
62
|
+
const ring = (border) => border === 'transparent' ? undefined : `inset 0 0 0 1px ${border}`;
|
|
63
|
+
const stateSx = (colors) => ({
|
|
64
|
+
backgroundColor: colors.fill,
|
|
65
|
+
color: colors.text,
|
|
66
|
+
boxShadow: ring(colors.border) ?? 'none',
|
|
67
|
+
});
|
|
89
68
|
const createButtonSx = (options) => theme => {
|
|
90
|
-
const config =
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const createButtonBaseSx = (config, options, iconOnlyPadding, iconOnlySize) => {
|
|
99
|
-
const padding = getButtonPadding(config, options, iconOnlyPadding);
|
|
69
|
+
const config = BUTTON_SIZE[options.size];
|
|
70
|
+
const pne = (0, createTheme_1.resolvePneSemanticPalette)(theme);
|
|
71
|
+
const colors = pne.button[options.variant];
|
|
72
|
+
const focusRing = [
|
|
73
|
+
ring(colors.default.border),
|
|
74
|
+
`0 0 0 2px ${theme.palette.background.default}`,
|
|
75
|
+
`0 0 0 4px ${pne.focusRing}`,
|
|
76
|
+
].filter(Boolean).join(', ');
|
|
100
77
|
return {
|
|
78
|
+
...stateSx(colors.default),
|
|
79
|
+
border: 'none',
|
|
101
80
|
borderRadius: '4px',
|
|
102
|
-
boxShadow: 'none',
|
|
103
81
|
boxSizing: 'border-box',
|
|
104
|
-
fontFamily:
|
|
105
|
-
fontSize:
|
|
106
|
-
fontWeight:
|
|
107
|
-
gap: options.iconOnly ? 0 : `${
|
|
108
|
-
height: options.iconOnly ? `${
|
|
109
|
-
lineHeight:
|
|
110
|
-
minHeight:
|
|
111
|
-
minWidth: options.iconOnly ? `${
|
|
112
|
-
padding
|
|
82
|
+
fontFamily: exports.PNE_BUTTON_FONT_FAMILY,
|
|
83
|
+
fontSize: `${config.fontSize}px`,
|
|
84
|
+
fontWeight: 500,
|
|
85
|
+
gap: options.iconOnly ? 0 : `${BUTTON_ICON_GAP}px`,
|
|
86
|
+
height: options.iconOnly ? `${config.height}px` : 'auto',
|
|
87
|
+
lineHeight: `${config.lineHeight}px`,
|
|
88
|
+
minHeight: `${config.height}px`,
|
|
89
|
+
minWidth: options.iconOnly ? `${config.height}px` : '0px',
|
|
90
|
+
padding: options.iconOnly ? 0 : `${config.paddingBlock}px ${config.paddingInline}px`,
|
|
91
|
+
textAlign: 'center',
|
|
113
92
|
textTransform: 'none',
|
|
114
|
-
|
|
115
|
-
'
|
|
116
|
-
|
|
93
|
+
transition: 'background-color 120ms linear, box-shadow 120ms linear, color 120ms linear',
|
|
94
|
+
whiteSpace: 'normal',
|
|
95
|
+
...(options.iconOnly ? { width: `${config.height}px`, flexShrink: 0 } : {}),
|
|
96
|
+
'&:hover, &[data-pne-state="hover"]': stateSx(colors.hover),
|
|
97
|
+
'&:active, &[data-pne-state="pressed"]': stateSx(colors.pressed),
|
|
98
|
+
'&.Mui-focusVisible, &[data-pne-state="focus"]': {
|
|
99
|
+
...stateSx(colors.default),
|
|
100
|
+
boxShadow: focusRing,
|
|
117
101
|
},
|
|
118
|
-
'
|
|
119
|
-
|
|
102
|
+
'&[data-pne-loading="true"]': {
|
|
103
|
+
...stateSx(colors.default),
|
|
104
|
+
cursor: 'progress',
|
|
105
|
+
pointerEvents: 'none',
|
|
120
106
|
},
|
|
107
|
+
'&.Mui-disabled': stateSx(colors.disabled),
|
|
121
108
|
'&&& .MuiButton-startIcon, &&& .MuiButton-endIcon': {
|
|
122
109
|
display: 'inline-flex',
|
|
123
110
|
marginLeft: 0,
|
|
124
111
|
marginRight: 0,
|
|
125
112
|
},
|
|
126
113
|
'&&& .MuiButton-startIcon > *:nth-of-type(1), &&& .MuiButton-endIcon > *:nth-of-type(1)': {
|
|
127
|
-
fontSize:
|
|
114
|
+
fontSize: config.icon,
|
|
128
115
|
},
|
|
129
116
|
'&&& .MuiButton-startIcon svg, &&& .MuiButton-endIcon svg': {
|
|
130
|
-
height:
|
|
131
|
-
width:
|
|
117
|
+
height: config.icon,
|
|
118
|
+
width: config.icon,
|
|
132
119
|
},
|
|
133
120
|
};
|
|
134
121
|
};
|
|
135
|
-
const getButtonPadding = (config, options, iconOnlyPadding) => {
|
|
136
|
-
if (options.iconOnly) {
|
|
137
|
-
return `${iconOnlyPadding}px`;
|
|
138
|
-
}
|
|
139
|
-
const compensateBorder = options.variant === 'outlined';
|
|
140
|
-
const verticalPadding = getButtonPaddingValue(config.verticalPadding, compensateBorder);
|
|
141
|
-
const horizontalPadding = getButtonPaddingValue(config.horizontalPadding, compensateBorder);
|
|
142
|
-
const iconNearPadding = getButtonPaddingValue(config.iconNearPadding, compensateBorder);
|
|
143
|
-
const iconFarPadding = getButtonPaddingValue(config.iconFarPadding, compensateBorder);
|
|
144
|
-
if (options.hasStartIcon) {
|
|
145
|
-
return `${verticalPadding}px ${iconFarPadding}px ${verticalPadding}px ${iconNearPadding}px`;
|
|
146
|
-
}
|
|
147
|
-
if (options.hasEndIcon) {
|
|
148
|
-
return `${verticalPadding}px ${iconNearPadding}px ${verticalPadding}px ${iconFarPadding}px`;
|
|
149
|
-
}
|
|
150
|
-
return `${verticalPadding}px ${horizontalPadding}px`;
|
|
151
|
-
};
|
|
152
|
-
const getButtonPaddingValue = (padding, compensateBorder) => {
|
|
153
|
-
return compensateBorder ? padding - outlinedBorderWidth : padding;
|
|
154
|
-
};
|
|
155
|
-
const createPrimaryButtonColorSx = (theme, variant, color) => {
|
|
156
|
-
if (color !== 'primary') {
|
|
157
|
-
return {};
|
|
158
|
-
}
|
|
159
|
-
const feedbackBackgroundColor = (0, styles_1.alpha)(theme.palette.primary.main, 0.1);
|
|
160
|
-
const isDarkMode = theme.palette.mode === 'dark';
|
|
161
|
-
const disabledBackground = isDarkMode ? theme.palette.action.disabledBackground : '#B0B7C3';
|
|
162
|
-
const disabledForeground = isDarkMode ? theme.palette.text.disabled : '#fff';
|
|
163
|
-
const disabledOutline = isDarkMode ? theme.palette.text.disabled : '#B0B7C3';
|
|
164
|
-
const brand = theme.palette.pne?.brand;
|
|
165
|
-
if (variant === 'contained') {
|
|
166
|
-
const fill = brand?.fill ?? theme.palette.primary.main;
|
|
167
|
-
const fillHover = isDarkMode && brand ? brand.fillHover : theme.palette.primary.dark;
|
|
168
|
-
const onFill = brand?.onFill ?? theme.palette.primary.contrastText;
|
|
169
|
-
const fillBorder = brand?.fillBorder ?? 'transparent';
|
|
170
|
-
const fillBoundary = fillBorder === 'transparent'
|
|
171
|
-
? 'none'
|
|
172
|
-
: `inset 0 0 0 1px ${fillBorder}`;
|
|
173
|
-
return {
|
|
174
|
-
backgroundColor: fill,
|
|
175
|
-
color: onFill,
|
|
176
|
-
boxShadow: fillBoundary,
|
|
177
|
-
'&:hover, &:active': {
|
|
178
|
-
backgroundColor: fillHover,
|
|
179
|
-
boxShadow: fillBoundary,
|
|
180
|
-
},
|
|
181
|
-
'&.Mui-disabled': {
|
|
182
|
-
backgroundColor: disabledBackground,
|
|
183
|
-
color: disabledForeground,
|
|
184
|
-
boxShadow: 'none',
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
if (variant === 'outlined') {
|
|
189
|
-
return {
|
|
190
|
-
backgroundColor: 'transparent',
|
|
191
|
-
borderColor: theme.palette.primary.main,
|
|
192
|
-
color: theme.palette.primary.main,
|
|
193
|
-
'&:hover, &:active': {
|
|
194
|
-
backgroundColor: feedbackBackgroundColor,
|
|
195
|
-
borderColor: theme.palette.primary.dark,
|
|
196
|
-
color: theme.palette.primary.dark,
|
|
197
|
-
},
|
|
198
|
-
'&.Mui-disabled': {
|
|
199
|
-
backgroundColor: 'transparent',
|
|
200
|
-
borderColor: disabledOutline,
|
|
201
|
-
color: disabledOutline,
|
|
202
|
-
},
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
if (variant === 'text') {
|
|
206
|
-
return {
|
|
207
|
-
color: theme.palette.primary.main,
|
|
208
|
-
'&:hover, &:active': {
|
|
209
|
-
backgroundColor: feedbackBackgroundColor,
|
|
210
|
-
color: theme.palette.primary.dark,
|
|
211
|
-
},
|
|
212
|
-
'&.Mui-disabled': {
|
|
213
|
-
backgroundColor: 'transparent',
|
|
214
|
-
color: disabledOutline,
|
|
215
|
-
},
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
return {};
|
|
219
|
-
};
|
|
220
122
|
exports.default = PneButton;
|
|
221
123
|
//# sourceMappingURL=PneButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PneButton.js","sourceRoot":"","sources":["../../src/component/PneButton.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PneButton.js","sourceRoot":"","sources":["../../src/component/PneButton.tsx"],"names":[],"mappings":";;;;AAAA,4CAAsD;AAKtD,qDAA8B;AAE9B,gDAAwD;AA8D3C,QAAA,sBAAsB,GAAG,+CAA+C,CAAA;AAErF,MAAM,cAAc,GAA6C;IAC7D,SAAS,EAAE,SAAS;IACpB,QAAQ,EAAE,SAAS;IACnB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,aAAa;IACpB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,MAAM;IACf,WAAW,EAAE,MAAM;IACnB,YAAY,EAAE,MAAM;IACpB,KAAK,EAAE,MAAM;CAChB,CAAA;AAYD,0EAA0E;AAC1E,MAAM,WAAW,GAA4C;IACzD,KAAK,EAAE,EAAC,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC;IAC9F,MAAM,EAAE,EAAC,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,aAAa,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC;IAChG,KAAK,EAAE,EAAC,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC;CACnG,CAAA;AAED,MAAM,eAAe,GAAG,CAAC,CAAA;AAEzB,MAAM,eAAe,GAAG,CAAC,IAAa,EAAyB,EAAE,CAC7D,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,OA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AC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,YAAY,MAAM,MAAM,CAAC,aAAa,IAAI;QACpF,SAAS,EAAE,QAAQ;QACnB,aAAa,EAAE,MAAM;QACrB,UAAU,EAAE,4EAA4E;QACxF,UAAU,EAAE,QAAQ;QACpB,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAC,KAAK,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,UAAU,EAAE,CAAC,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACzE,oCAAoC,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;QAC3D,uCAAuC,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;QAChE,+CAA+C,EAAE;YAC7C,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;YAC1B,SAAS,EAAE,SAAS;SACvB;QACD,4BAA4B,EAAE;YAC1B,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;YAC1B,MAAM,EAAE,UAAU;YAClB,aAAa,EAAE,MAAM;SACxB;QACD,gBAAgB,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC1C,kDAAkD,EAAE;YAChD,OAAO,EAAE,aAAa;YACtB,UAAU,EAAE,CAAC;YACb,WAAW,EAAE,CAAC;SACjB;QACD,wFAAwF,EAAE;YACtF,QAAQ,EAAE,MAAM,CAAC,IAAI;SACxB;QACD,0DAA0D,EAAE;YACxD,MAAM,EAAE,MAAM,CAAC,IAAI;YACnB,KAAK,EAAE,MAAM,CAAC,IAAI;SACrB;KACwB,CAAA;AACjC,CAAC,CAAA;AAED,kBAAe,SAAS,CAAA"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { CheckboxProps } from '@mui/material';
|
|
3
|
+
export type PneCheckboxSize = NonNullable<CheckboxProps['size']>;
|
|
3
4
|
export interface PneCheckboxProps extends CheckboxProps {
|
|
4
5
|
inputRef?: React.Ref<HTMLInputElement>;
|
|
6
|
+
/** A state pinned for specimens; product code never sets it. */
|
|
7
|
+
'data-pne-state'?: 'hover' | 'pressed' | 'focus';
|
|
5
8
|
}
|
|
6
9
|
export declare const PneCheckbox: React.ForwardRefExoticComponent<Omit<PneCheckboxProps, "ref"> & React.RefAttributes<HTMLSpanElement>>;
|
|
@@ -7,6 +7,7 @@ const material_1 = require("@mui/material");
|
|
|
7
7
|
const DefaultPropsProvider_1 = require("@mui/material/DefaultPropsProvider");
|
|
8
8
|
const styles_1 = require("@mui/material/styles");
|
|
9
9
|
const DefaultPropsProvider_2 = tslib_1.__importDefault(require("@mui/system/DefaultPropsProvider"));
|
|
10
|
+
const createTheme_1 = require("../createTheme");
|
|
10
11
|
const PneFieldContext_1 = require("./PneFieldContext");
|
|
11
12
|
const PneToggleInput_1 = require("./PneToggleInput");
|
|
12
13
|
exports.PneCheckbox = (0, react_1.forwardRef)((props, ref) => {
|
|
@@ -29,7 +30,9 @@ exports.PneCheckbox = (0, react_1.forwardRef)((props, ref) => {
|
|
|
29
30
|
},
|
|
30
31
|
});
|
|
31
32
|
const componentsWithoutCheckboxDefaults = useComponentsWithoutCheckboxDefaults();
|
|
32
|
-
const {
|
|
33
|
+
const { checkedIcon, 'data-pne-state': pinnedState, disabled,
|
|
34
|
+
// The box shows hover, press and focus itself (UI Kit); an explicit false brings MUI's back.
|
|
35
|
+
disableRipple = true, icon, id, indeterminate = false, indeterminateIcon, inputRef, readOnly = false, required, sx, size = 'small', slotProps, ...rest } = themedProps;
|
|
33
36
|
const { inputAriaProps, rootProps } = (0, PneToggleInput_1.moveAriaPropsToInput)(rest);
|
|
34
37
|
const controlProps = (0, PneFieldContext_1.usePneFieldControlProps)({
|
|
35
38
|
ariaDescribedBy: inputAriaProps['aria-describedby'],
|
|
@@ -56,19 +59,23 @@ exports.PneCheckbox = (0, react_1.forwardRef)((props, ref) => {
|
|
|
56
59
|
mergeClassNameAndStyle: theme.components?.mergeClassNameAndStyle,
|
|
57
60
|
readOnly,
|
|
58
61
|
});
|
|
62
|
+
// The error look follows the field error and an explicit aria-invalid alike.
|
|
63
|
+
const invalid = controlProps.error === true || isAriaInvalid(inputAriaProps['aria-invalid']);
|
|
59
64
|
const _sx = [
|
|
60
|
-
|
|
65
|
+
checkboxSx,
|
|
66
|
+
...(Array.isArray(sx) ? sx : [sx]),
|
|
61
67
|
];
|
|
62
68
|
// MUI still declares Checkbox's forwarded ref as a button even though
|
|
63
69
|
// SwitchBase renders its root as a span. Keep that mismatch inside PNE.
|
|
64
70
|
const muiRootRef = ref;
|
|
65
71
|
return react_1.default.createElement(DefaultPropsProvider_2.default, { value: componentsWithoutCheckboxDefaults },
|
|
66
|
-
react_1.default.createElement(material_1.Checkbox, { ...rootProps, disabled: controlProps.disabled ?? disabled, id: controlProps.id ?? id, indeterminate: indeterminate, readOnly: readOnly, ref: muiRootRef, required: controlProps.required ?? required, size: size, slotProps: {
|
|
72
|
+
react_1.default.createElement(material_1.Checkbox, { ...rootProps, checkedIcon: checkedIcon ?? react_1.default.createElement(PneCheckboxBox, { value: 'on' }), "data-pne-error": invalid || undefined, "data-pne-readonly": readOnly || undefined, "data-pne-state": pinnedState, disableRipple: disableRipple, disabled: controlProps.disabled ?? disabled, icon: icon ?? react_1.default.createElement(PneCheckboxBox, { value: 'off' }), id: controlProps.id ?? id, indeterminate: indeterminate, indeterminateIcon: indeterminateIcon ?? react_1.default.createElement(PneCheckboxBox, { value: 'indeterminate' }), readOnly: readOnly, ref: muiRootRef, required: controlProps.required ?? required, size: size, slotProps: {
|
|
67
73
|
...slotProps,
|
|
68
74
|
input: inputSlotProps,
|
|
69
75
|
}, sx: _sx }));
|
|
70
76
|
});
|
|
71
77
|
exports.PneCheckbox.displayName = 'PneCheckbox';
|
|
78
|
+
const isAriaInvalid = (value) => value === true || value === 'true';
|
|
72
79
|
const useComponentsWithoutCheckboxDefaults = () => {
|
|
73
80
|
const theme = (0, styles_1.useTheme)();
|
|
74
81
|
return (0, react_1.useMemo)(() => {
|
|
@@ -87,4 +94,95 @@ const useComponentsWithoutCheckboxDefaults = () => {
|
|
|
87
94
|
};
|
|
88
95
|
}, [theme.components]);
|
|
89
96
|
};
|
|
97
|
+
const RING_WIDTH = 1.5;
|
|
98
|
+
// The square sits 1px inside the box and the ring is drawn on its inner edge.
|
|
99
|
+
const RING_INSET = 1 + RING_WIDTH / 2;
|
|
100
|
+
// UI Kit Checkbox: sm 16, md 20 and, as in the Figma matrix, lg 24; the check and the bar are
|
|
101
|
+
// the UI Kit glyphs placed in the box.
|
|
102
|
+
const BOX_GEOMETRY = {
|
|
103
|
+
small: { size: 16, radius: 2.25, check: 'M4.2 8.2 L6.6 10.6 L11.8 5.4', checkWidth: 1.5, bar: 'M4.75 8 H11.25', barWidth: 1.5 },
|
|
104
|
+
medium: { size: 20, radius: 2.25, check: 'M5 10.2 L8.2 13.4 L15 6.6', checkWidth: 1.5, bar: 'M6 10 H14', barWidth: 2 },
|
|
105
|
+
large: { size: 24, radius: 3.25, check: 'M5.9 12.2 L9.8 16.1 L18.1 7.8', checkWidth: 2, bar: 'M7.25 12 H16.75', barWidth: 2.5 },
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* The box MUI renders as `icon`, `checkedIcon` or `indeterminateIcon`. MUI hands it the checkbox
|
|
109
|
+
* size as `fontSize`; the colours come from the root's rules.
|
|
110
|
+
*/
|
|
111
|
+
const PneCheckboxBox = ({ fontSize, value }) => {
|
|
112
|
+
const geometry = BOX_GEOMETRY[fontSize] ?? BOX_GEOMETRY.medium;
|
|
113
|
+
const square = geometry.size - 2 * RING_INSET;
|
|
114
|
+
return react_1.default.createElement("svg", { "aria-hidden": true, className: `PneCheckbox-box PneCheckbox-${value === 'off' ? 'off' : 'on'}`, height: geometry.size, viewBox: `0 0 ${geometry.size} ${geometry.size}`, width: geometry.size },
|
|
115
|
+
react_1.default.createElement("rect", { className: 'PneCheckbox-square', height: square, rx: geometry.radius, strokeWidth: RING_WIDTH, width: square, x: RING_INSET, y: RING_INSET }),
|
|
116
|
+
value === 'off' ? null : react_1.default.createElement("path", { className: 'PneCheckbox-mark', d: value === 'on' ? geometry.check : geometry.bar, fill: 'none', strokeLinecap: 'round', strokeLinejoin: 'round', strokeWidth: value === 'on' ? geometry.checkWidth : geometry.barWidth }));
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Colours of one state as custom properties on the root; the box rules read them. The root colour
|
|
120
|
+
* is the ring of an off box and the fill of an on one, so a `color` override recolours the box as
|
|
121
|
+
* it did MUI's icons.
|
|
122
|
+
*/
|
|
123
|
+
const stateColors = (palette, state) => {
|
|
124
|
+
const off = palette.off[state];
|
|
125
|
+
const on = palette.on[state];
|
|
126
|
+
return {
|
|
127
|
+
'--pne-checkbox-off-fill': off.fill,
|
|
128
|
+
'--pne-checkbox-off-ring': off.ring,
|
|
129
|
+
'--pne-checkbox-on-fill': on.fill,
|
|
130
|
+
'--pne-checkbox-on-ring': on.ring === 'transparent' ? 'currentColor' : on.ring,
|
|
131
|
+
'--pne-checkbox-mark': on.mark,
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
// Hover and press change nothing on an inert or invalid box: the error look stays (UI Kit).
|
|
135
|
+
const INTERACTIVE_ROOT = '&:not(.Mui-disabled):not([data-pne-readonly]):not([data-pne-error])';
|
|
136
|
+
// Geometry lives in the box itself (it gets the size from MUI); the rules here are colours only.
|
|
137
|
+
// One rule per state keeps the style small: tables render a checkbox in every row.
|
|
138
|
+
const checkboxSx = theme => {
|
|
139
|
+
const pne = (0, createTheme_1.resolvePneSemanticPalette)(theme);
|
|
140
|
+
const colors = pne.checkbox;
|
|
141
|
+
const focusRing = `0 0 0 2px ${theme.palette.background.default}, 0 0 0 4px ${pne.focusRing}`;
|
|
142
|
+
return {
|
|
143
|
+
// MUI's hit area stays: 38 around the small box, 42 around the medium one (large: 46).
|
|
144
|
+
padding: '11px',
|
|
145
|
+
transition: 'color 120ms linear',
|
|
146
|
+
color: 'var(--pne-checkbox-off-ring)',
|
|
147
|
+
// Later states win: default, hover, pressed, error, read-only, disabled.
|
|
148
|
+
...stateColors(colors, 'default'),
|
|
149
|
+
[`${INTERACTIVE_ROOT}:hover`]: stateColors(colors, 'hover'),
|
|
150
|
+
'&[data-pne-state="hover"]': stateColors(colors, 'hover'),
|
|
151
|
+
[`${INTERACTIVE_ROOT}:active`]: stateColors(colors, 'pressed'),
|
|
152
|
+
'&[data-pne-state="pressed"]': stateColors(colors, 'pressed'),
|
|
153
|
+
'&[data-pne-error]': stateColors(colors, 'error'),
|
|
154
|
+
'&[data-pne-readonly]': { ...stateColors(colors, 'readOnly'), cursor: 'default' },
|
|
155
|
+
// MUI greys a disabled root; the variables take over, and the on colour below still wins.
|
|
156
|
+
'&.Mui-disabled': { ...stateColors(colors, 'disabled'), color: 'var(--pne-checkbox-off-ring)' },
|
|
157
|
+
'&.Mui-checked, &.MuiCheckbox-indeterminate': { color: 'var(--pne-checkbox-on-fill)' },
|
|
158
|
+
'& .PneCheckbox-box': {
|
|
159
|
+
borderRadius: '4px',
|
|
160
|
+
display: 'block',
|
|
161
|
+
flexShrink: 0,
|
|
162
|
+
},
|
|
163
|
+
'& .PneCheckbox-square': {
|
|
164
|
+
transition: 'fill 120ms linear, stroke 120ms linear',
|
|
165
|
+
},
|
|
166
|
+
'& .PneCheckbox-off .PneCheckbox-square': {
|
|
167
|
+
fill: 'var(--pne-checkbox-off-fill)',
|
|
168
|
+
stroke: 'currentColor',
|
|
169
|
+
},
|
|
170
|
+
'& .PneCheckbox-on .PneCheckbox-square': {
|
|
171
|
+
fill: 'currentColor',
|
|
172
|
+
stroke: 'var(--pne-checkbox-on-ring)',
|
|
173
|
+
},
|
|
174
|
+
'& .PneCheckbox-on .PneCheckbox-mark': {
|
|
175
|
+
stroke: 'var(--pne-checkbox-mark)',
|
|
176
|
+
},
|
|
177
|
+
'&.Mui-focusVisible .PneCheckbox-box, &[data-pne-state="focus"] .PneCheckbox-box': {
|
|
178
|
+
boxShadow: focusRing,
|
|
179
|
+
},
|
|
180
|
+
'@media (prefers-reduced-motion: reduce)': {
|
|
181
|
+
transition: 'none',
|
|
182
|
+
'& .PneCheckbox-square': {
|
|
183
|
+
transition: 'none',
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
};
|
|
90
188
|
//# sourceMappingURL=PneCheckbox.js.map
|