@itwin/itwinui-react 3.4.1 → 3.5.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/CHANGELOG.md +24 -0
- package/cjs/core/ProgressIndicators/ProgressLinear.js +6 -1
- package/cjs/core/ProgressIndicators/ProgressRadial.js +8 -3
- package/cjs/core/Select/Select.d.ts +3 -1
- package/cjs/core/Select/Select.js +1 -1
- package/cjs/core/ToggleSwitch/ToggleSwitch.d.ts +4 -2
- package/cjs/core/ToggleSwitch/ToggleSwitch.js +5 -11
- package/cjs/core/Typography/Anchor.d.ts +21 -1
- package/cjs/core/Typography/Anchor.js +38 -3
- package/cjs/core/VisuallyHidden/VisuallyHidden.js +19 -3
- package/cjs/core/utils/components/ShadowRoot.d.ts +2 -1
- package/cjs/core/utils/components/ShadowRoot.js +19 -4
- package/cjs/core/utils/functions/polymorphic.d.ts +5 -3
- package/cjs/core/utils/functions/polymorphic.js +20 -5
- package/cjs/core/utils/icons/Svg.js +5 -1
- package/esm/core/ProgressIndicators/ProgressLinear.js +7 -2
- package/esm/core/ProgressIndicators/ProgressRadial.js +9 -4
- package/esm/core/Select/Select.d.ts +3 -1
- package/esm/core/Select/Select.js +1 -1
- package/esm/core/ToggleSwitch/ToggleSwitch.d.ts +4 -2
- package/esm/core/ToggleSwitch/ToggleSwitch.js +6 -12
- package/esm/core/Typography/Anchor.d.ts +21 -1
- package/esm/core/Typography/Anchor.js +11 -2
- package/esm/core/VisuallyHidden/VisuallyHidden.js +19 -3
- package/esm/core/utils/components/ShadowRoot.d.ts +2 -1
- package/esm/core/utils/components/ShadowRoot.js +19 -4
- package/esm/core/utils/functions/polymorphic.d.ts +5 -3
- package/esm/core/utils/functions/polymorphic.js +20 -5
- package/esm/core/utils/icons/Svg.js +5 -1
- package/package.json +4 -4
- package/styles.css +34 -33
|
@@ -6,24 +6,39 @@ import * as React from 'react';
|
|
|
6
6
|
import * as ReactDOM from 'react-dom';
|
|
7
7
|
const isBrowser = typeof document !== 'undefined';
|
|
8
8
|
const supportsDSD = isBrowser && 'shadowRootMode' in HTMLTemplateElement.prototype;
|
|
9
|
+
const supportsAdoptedStylesheets = isBrowser && 'adoptedStyleSheets' in Document.prototype;
|
|
9
10
|
/**
|
|
10
11
|
* Wrapper around `<template>` element that attaches shadow root to its parent
|
|
11
12
|
* and moves its children into the shadow root.
|
|
12
13
|
*
|
|
13
14
|
* @private
|
|
14
15
|
*/
|
|
15
|
-
export const ShadowRoot = ({ children }) => {
|
|
16
|
+
export const ShadowRoot = ({ children, css, }) => {
|
|
16
17
|
const [shadowRoot, setShadowRoot] = React.useState();
|
|
17
18
|
const isFirstRender = useIsFirstRender();
|
|
19
|
+
const styleSheet = React.useRef();
|
|
18
20
|
const attachShadowRef = React.useCallback((template) => {
|
|
19
21
|
const parent = template?.parentElement;
|
|
20
22
|
if (!template || !parent) {
|
|
21
23
|
return;
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
if (parent.shadowRoot) {
|
|
26
|
+
parent.shadowRoot.replaceChildren(); // Remove previous shadowroot content
|
|
27
|
+
}
|
|
28
|
+
queueMicrotask(() => {
|
|
29
|
+
const shadow = parent.shadowRoot || parent.attachShadow({ mode: 'open' });
|
|
30
|
+
if (css && supportsAdoptedStylesheets) {
|
|
31
|
+
styleSheet.current || (styleSheet.current = new CSSStyleSheet());
|
|
32
|
+
styleSheet.current.replaceSync(css);
|
|
33
|
+
shadow.adoptedStyleSheets = [styleSheet.current];
|
|
34
|
+
}
|
|
35
|
+
ReactDOM.flushSync(() => setShadowRoot(shadow));
|
|
36
|
+
});
|
|
37
|
+
}, [css]);
|
|
25
38
|
if (!isBrowser) {
|
|
26
|
-
return React.createElement("template", { shadowrootmode: 'open' },
|
|
39
|
+
return (React.createElement("template", { shadowrootmode: 'open' },
|
|
40
|
+
css && React.createElement("style", null, css),
|
|
41
|
+
children));
|
|
27
42
|
}
|
|
28
43
|
// In browsers that support DSD, the template will be automatically removed as soon as it's parsed.
|
|
29
44
|
// To pass hydration, the first client render needs to emulate this browser behavior and return null.
|
|
@@ -3,11 +3,13 @@ import type { PolymorphicForwardRefComponent } from '../props.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Utility to create a type-safe polymorphic component with a simple class.
|
|
5
5
|
*
|
|
6
|
-
* Can be called directly or as a property of the `
|
|
6
|
+
* Can be called directly or as a property of the `polymorphic` object.
|
|
7
7
|
* In both cases, returns a component that:
|
|
8
|
+
* - uses CSS-modules scoped classes
|
|
8
9
|
* - supports `as` prop with default element
|
|
9
|
-
* - forwards ref and rest props
|
|
10
|
-
* - adds and merges
|
|
10
|
+
* - forwards ref and spreads rest props
|
|
11
|
+
* - adds and merges CSS classes
|
|
12
|
+
* - adds tabIndex to interactive elements (Safari workaround)
|
|
11
13
|
*
|
|
12
14
|
* @example
|
|
13
15
|
* const MyPolyDiv = polymorphic('my-poly-div');
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
6
|
import * as React from 'react';
|
|
6
7
|
import cx from 'classnames';
|
|
7
8
|
import { useGlobals } from '../hooks/useGlobals.js';
|
|
@@ -9,9 +10,21 @@ import styles from '../../../styles.js';
|
|
|
9
10
|
const _base = (defaultElement) => {
|
|
10
11
|
return (className, attrs) => {
|
|
11
12
|
const Comp = React.forwardRef(({ as = defaultElement, ...props }, ref) => {
|
|
12
|
-
|
|
13
|
+
props = {
|
|
14
|
+
...attrs,
|
|
15
|
+
...props,
|
|
16
|
+
className: getScopedClassName(cx(className, attrs?.className, props.className)),
|
|
17
|
+
};
|
|
18
|
+
const Element = as || 'div';
|
|
19
|
+
// Add tabIndex to interactive elements if not already set.
|
|
20
|
+
// Workaround for Safari refusing to focus links/buttons/non-text inputs.
|
|
21
|
+
if (Element === 'button' ||
|
|
22
|
+
Element === 'a' ||
|
|
23
|
+
(Element === 'input' && props.type === 'checkbox')) {
|
|
24
|
+
props.tabIndex ?? (props.tabIndex = 0);
|
|
25
|
+
}
|
|
13
26
|
useGlobals();
|
|
14
|
-
return
|
|
27
|
+
return React.createElement(Element, { ref: ref, ...props });
|
|
15
28
|
});
|
|
16
29
|
Comp.displayName = getDisplayNameFromClass(className);
|
|
17
30
|
return Comp;
|
|
@@ -20,11 +33,13 @@ const _base = (defaultElement) => {
|
|
|
20
33
|
/**
|
|
21
34
|
* Utility to create a type-safe polymorphic component with a simple class.
|
|
22
35
|
*
|
|
23
|
-
* Can be called directly or as a property of the `
|
|
36
|
+
* Can be called directly or as a property of the `polymorphic` object.
|
|
24
37
|
* In both cases, returns a component that:
|
|
38
|
+
* - uses CSS-modules scoped classes
|
|
25
39
|
* - supports `as` prop with default element
|
|
26
|
-
* - forwards ref and rest props
|
|
27
|
-
* - adds and merges
|
|
40
|
+
* - forwards ref and spreads rest props
|
|
41
|
+
* - adds and merges CSS classes
|
|
42
|
+
* - adds tabIndex to interactive elements (Safari workaround)
|
|
28
43
|
*
|
|
29
44
|
* @example
|
|
30
45
|
* const MyPolyDiv = polymorphic('my-poly-div');
|
|
@@ -3,4 +3,8 @@
|
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { polymorphic } from '../functions/polymorphic.js';
|
|
6
|
-
export const Svg = polymorphic.svg('', {
|
|
6
|
+
export const Svg = polymorphic.svg('', {
|
|
7
|
+
viewBox: '0 0 16 16',
|
|
8
|
+
width: 16,
|
|
9
|
+
height: 16,
|
|
10
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/itwinui-react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"author": "Bentley Systems",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -80,14 +80,13 @@
|
|
|
80
80
|
"@floating-ui/react": "^0.26.3",
|
|
81
81
|
"@itwin/itwinui-illustrations-react": "^2.1.0",
|
|
82
82
|
"classnames": "^2.3.2",
|
|
83
|
-
"jsdom": "^24.0.0",
|
|
84
83
|
"react-table": "^7.8.0",
|
|
85
84
|
"react-transition-group": "^4.4.5",
|
|
86
85
|
"tslib": "^2.6.0"
|
|
87
86
|
},
|
|
88
87
|
"devDependencies": {
|
|
89
|
-
"@itwin/itwinui-css": "^2.
|
|
90
|
-
"@itwin/itwinui-variables": "3.
|
|
88
|
+
"@itwin/itwinui-css": "^2.4.0",
|
|
89
|
+
"@itwin/itwinui-variables": "3.1.0",
|
|
91
90
|
"@swc/cli": "^0.1.62",
|
|
92
91
|
"@swc/core": "^1.3.68",
|
|
93
92
|
"@testing-library/jest-dom": "^6.3.0",
|
|
@@ -101,6 +100,7 @@
|
|
|
101
100
|
"eslint": "^8",
|
|
102
101
|
"eslint-config-prettier": "^8.8.0",
|
|
103
102
|
"eslint-plugin-require-extensions": "^0.1.3",
|
|
103
|
+
"jsdom": "^24.0.0",
|
|
104
104
|
"react": "^18.0.0",
|
|
105
105
|
"react-dom": "^18.0.0",
|
|
106
106
|
"typescript": "~5.1.6",
|