@datalayer/primer-addons 1.0.61 → 1.0.62

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.
@@ -4,7 +4,7 @@ export type ScrollAreaProps = ComponentProps<typeof Box>;
4
4
  /**
5
5
  * A Box that scrolls (vertically by default) with the discreet scrollbar
6
6
  * (`scrollbarSx`), its scroll kept to itself. Any `sx` given is applied
7
- * over it.
7
+ * over it, a `scrollbarWidth` or `scrollbarColor` included (`withScrollbarSx`).
8
8
  */
9
9
  export declare const ScrollArea: import("react").ForwardRefExoticComponent<Omit<import("..").BoxStyleProps & {
10
10
  hover?: import("..").BoxStyleProps | undefined;
@@ -5,13 +5,13 @@ import { jsx as _jsx } from "react/jsx-runtime";
5
5
  */
6
6
  import { forwardRef } from 'react';
7
7
  import { Box } from '../box/Box';
8
- import { scrollbarSx } from './scrollbar';
8
+ import { withScrollbarSx } from './scrollbar';
9
9
  /**
10
10
  * A Box that scrolls (vertically by default) with the discreet scrollbar
11
11
  * (`scrollbarSx`), its scroll kept to itself. Any `sx` given is applied
12
- * over it.
12
+ * over it, a `scrollbarWidth` or `scrollbarColor` included (`withScrollbarSx`).
13
13
  */
14
14
  export const ScrollArea = forwardRef(function ScrollArea({ sx, ...props }, ref) {
15
- return (_jsx(Box, { ref: ref, ...props, sx: { overflowY: 'auto', overscrollBehavior: 'contain', ...scrollbarSx, ...sx } }));
15
+ return (_jsx(Box, { ref: ref, ...props, sx: { overflowY: 'auto', overscrollBehavior: 'contain', ...withScrollbarSx(sx) } }));
16
16
  });
17
17
  export default ScrollArea;
@@ -55,6 +55,15 @@ export declare const scrollbarSx: {
55
55
  readonly backgroundColor: "var(--dla-scrollbar-thumb-hover, var(--fgColor-muted, rgba(127, 127, 127, 0.7)))";
56
56
  };
57
57
  };
58
+ /**
59
+ * `scrollbarSx` with an element's own `sx` over it. A `scrollbarWidth` or
60
+ * `scrollbarColor` given in `sx` goes into both of the scrollbar's
61
+ * `@supports` branches too: set at the element's top level only, the
62
+ * branches, which come after it, would put the scrollbar's values back.
63
+ * The element's own `@supports` blocks of the same conditions come last,
64
+ * whole.
65
+ */
66
+ export declare function withScrollbarSx<T extends object>(sx?: T): typeof scrollbarSx & T;
58
67
  /**
59
68
  * The scrollbar as a stylesheet, for the elements a selector matches (a
60
69
  * selector list too: each part gets it). `'*'` is every element of the page.
@@ -51,24 +51,91 @@ export const scrollbarSx = {
51
51
  },
52
52
  '&::-webkit-scrollbar-thumb:hover': { backgroundColor: THUMB_HOVER },
53
53
  };
54
- /** A selector list split at its top-level commas (not those in `:is(a, b)`). */
54
+ /** Unset as `Box` reads it: no declaration (`null`, `undefined`, `false`, `''`). */
55
+ const isSet = (value) => value !== null && value !== undefined && value !== false && value !== '';
56
+ /**
57
+ * A `scrollbarWidth` or `scrollbarColor` of the element's own over a
58
+ * branch's default: an unset value keeps the default, and so does an
59
+ * unset base of a responsive array (its later values still apply).
60
+ */
61
+ function over(own, fallback) {
62
+ if (Array.isArray(own)) {
63
+ return isSet(own[0]) ? own : [fallback, ...own.slice(1)];
64
+ }
65
+ return isSet(own) ? own : fallback;
66
+ }
67
+ /**
68
+ * `scrollbarSx` with an element's own `sx` over it. A `scrollbarWidth` or
69
+ * `scrollbarColor` given in `sx` goes into both of the scrollbar's
70
+ * `@supports` branches too: set at the element's top level only, the
71
+ * branches, which come after it, would put the scrollbar's values back.
72
+ * The element's own `@supports` blocks of the same conditions come last,
73
+ * whole.
74
+ */
75
+ export function withScrollbarSx(sx) {
76
+ const own = (sx ?? {});
77
+ const branch = (condition) => {
78
+ const defaults = scrollbarSx[condition];
79
+ return {
80
+ ...defaults,
81
+ scrollbarWidth: over(own.scrollbarWidth, defaults.scrollbarWidth),
82
+ scrollbarColor: over(own.scrollbarColor, defaults.scrollbarColor),
83
+ ...(own[condition] ?? {}),
84
+ };
85
+ };
86
+ return {
87
+ ...scrollbarSx,
88
+ ...sx,
89
+ [WEBKIT]: branch(WEBKIT),
90
+ [STANDARD]: branch(STANDARD),
91
+ };
92
+ }
93
+ /**
94
+ * A selector list split at its top-level commas: not those in `:is(a, b)`
95
+ * or `[a="b"]`, in quotes, escaped (`\,`) or in a comment (which is dropped).
96
+ */
55
97
  function selectorsOf(selector) {
56
98
  const parts = [];
57
99
  let depth = 0;
58
- let start = 0;
100
+ let quote = '';
101
+ let part = '';
59
102
  for (let i = 0; i < selector.length; i++) {
60
103
  const c = selector[i];
61
- if (c === '(' || c === '[')
62
- depth++;
63
- else if (c === ')' || c === ']')
64
- depth--;
104
+ if (c === '\\') {
105
+ part += c + (selector[i + 1] ?? '');
106
+ i++;
107
+ }
108
+ else if (quote) {
109
+ part += c;
110
+ if (c === quote)
111
+ quote = '';
112
+ }
113
+ else if (c === '/' && selector[i + 1] === '*') {
114
+ const end = selector.indexOf('*/', i + 2);
115
+ i = end === -1 ? selector.length : end + 1;
116
+ // A hex escape the comment ended (`\31/**/ .b`) is ended by a space
117
+ // in its place, which CSS consumes: the whitespace after it stays.
118
+ if (/(^|[^\\])(\\\\)*\\[0-9a-fA-F]{1,6}$/.test(part))
119
+ part += ' ';
120
+ }
121
+ else if (c === '"' || c === "'") {
122
+ quote = c;
123
+ part += c;
124
+ }
65
125
  else if (c === ',' && depth === 0) {
66
- parts.push(selector.slice(start, i));
67
- start = i + 1;
126
+ parts.push(part);
127
+ part = '';
128
+ }
129
+ else {
130
+ if (c === '(' || c === '[')
131
+ depth++;
132
+ else if ((c === ')' || c === ']') && depth > 0)
133
+ depth--;
134
+ part += c;
68
135
  }
69
136
  }
70
- parts.push(selector.slice(start));
71
- return parts.map(part => part.trim()).filter(Boolean);
137
+ parts.push(part);
138
+ return parts.map(p => p.trim()).filter(Boolean);
72
139
  }
73
140
  /**
74
141
  * The scrollbar as a stylesheet, for the elements a selector matches (a
@@ -97,6 +97,13 @@ export function primerComponentsCss(shape = {}) {
97
97
  color: var(--fgColor-accent);
98
98
  font-weight: 600;
99
99
  }
100
+ :scope ${sel.select} option:disabled,
101
+ :scope ${sel.select} optgroup:disabled option {
102
+ background-color: transparent;
103
+ color: var(--fgColor-disabled);
104
+ font-weight: normal;
105
+ cursor: not-allowed;
106
+ }
100
107
  }`);
101
108
  }
102
109
  if (shape.radiusTable !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalayer/primer-addons",
3
- "version": "1.0.61",
3
+ "version": "1.0.62",
4
4
  "license": "BSD-3-Clause",
5
5
  "scripts": {
6
6
  "build": "npm run build:lib",