@itwin/itwinui-react 3.4.2 → 3.6.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 +46 -0
- package/cjs/core/Carousel/Carousel.d.ts +4 -4
- package/cjs/core/Carousel/CarouselNavigation.d.ts +4 -4
- package/cjs/core/Dialog/Dialog.js +19 -17
- package/cjs/core/Dialog/DialogContext.d.ts +4 -0
- package/cjs/core/Dialog/DialogMain.js +1 -1
- package/cjs/core/Dialog/DialogTitleBar.js +1 -1
- package/cjs/core/InputGroup/InputGroup.d.ts +4 -0
- package/cjs/core/InputGroup/InputGroup.js +20 -4
- package/cjs/core/InputWithDecorations/InputWithDecorations.d.ts +18 -62
- package/cjs/core/InputWithDecorations/InputWithDecorations.js +21 -6
- package/cjs/core/LabeledSelect/LabeledSelect.d.ts +376 -4
- package/cjs/core/LabeledSelect/LabeledSelect.js +1 -1
- package/cjs/core/Popover/Popover.d.ts +6 -3
- package/cjs/core/ProgressIndicators/ProgressLinear.js +6 -1
- package/cjs/core/ProgressIndicators/ProgressRadial.js +8 -3
- package/cjs/core/SearchBox/SearchBox.js +4 -6
- package/cjs/core/Select/Select.d.ts +197 -102
- package/cjs/core/Select/Select.js +72 -19
- package/cjs/core/Table/Table.js +2 -1
- package/cjs/core/Tabs/Tabs.js +19 -3
- package/cjs/core/Tile/Tile.d.ts +2 -2
- 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/InputFlexContainer.d.ts +25 -0
- package/cjs/core/utils/components/InputFlexContainer.js +19 -1
- package/cjs/core/utils/components/LineClamp.d.ts +5 -0
- package/cjs/core/utils/components/LineClamp.js +49 -0
- package/cjs/core/utils/components/ShadowRoot.d.ts +2 -1
- package/cjs/core/utils/components/ShadowRoot.js +19 -4
- package/cjs/core/utils/components/index.d.ts +1 -0
- package/cjs/core/utils/components/index.js +1 -0
- 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/cjs/core/utils/icons/SvgStatusError.js +1 -1
- package/esm/core/Carousel/Carousel.d.ts +4 -4
- package/esm/core/Carousel/CarouselNavigation.d.ts +4 -4
- package/esm/core/Dialog/Dialog.js +19 -17
- package/esm/core/Dialog/DialogContext.d.ts +4 -0
- package/esm/core/Dialog/DialogMain.js +1 -1
- package/esm/core/Dialog/DialogTitleBar.js +1 -1
- package/esm/core/InputGroup/InputGroup.d.ts +4 -0
- package/esm/core/InputGroup/InputGroup.js +20 -4
- package/esm/core/InputWithDecorations/InputWithDecorations.d.ts +18 -62
- package/esm/core/InputWithDecorations/InputWithDecorations.js +22 -7
- package/esm/core/LabeledSelect/LabeledSelect.d.ts +376 -4
- package/esm/core/LabeledSelect/LabeledSelect.js +1 -1
- package/esm/core/Popover/Popover.d.ts +6 -3
- package/esm/core/ProgressIndicators/ProgressLinear.js +7 -2
- package/esm/core/ProgressIndicators/ProgressRadial.js +9 -4
- package/esm/core/SearchBox/SearchBox.js +5 -7
- package/esm/core/Select/Select.d.ts +197 -102
- package/esm/core/Select/Select.js +73 -20
- package/esm/core/Table/Table.js +2 -1
- package/esm/core/Tabs/Tabs.js +19 -3
- package/esm/core/Tile/Tile.d.ts +2 -2
- 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/InputFlexContainer.d.ts +25 -0
- package/esm/core/utils/components/InputFlexContainer.js +18 -0
- package/esm/core/utils/components/LineClamp.d.ts +5 -0
- package/esm/core/utils/components/LineClamp.js +23 -0
- package/esm/core/utils/components/ShadowRoot.d.ts +2 -1
- package/esm/core/utils/components/ShadowRoot.js +19 -4
- package/esm/core/utils/components/index.d.ts +1 -0
- package/esm/core/utils/components/index.js +1 -0
- 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/esm/core/utils/icons/SvgStatusError.js +1 -1
- package/package.json +27 -27
- package/styles.css +39 -38
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import cx from 'classnames';
|
|
7
|
-
import {
|
|
7
|
+
import { Box, SvgCheckmark } from '../utils/index.js';
|
|
8
8
|
/**
|
|
9
9
|
* A switch for turning on and off.
|
|
10
10
|
* @example
|
|
@@ -24,21 +24,15 @@ import { useMergedRefs, Box } from '../utils/index.js';
|
|
|
24
24
|
* <ToggleSwitch label='With icon toggle' icon={<svg viewBox='0 0 16 16'><path d='M1 1v14h14V1H1zm13 1.7v10.6L8.7 8 14 2.7zM8 7.3L2.7 2h10.6L8 7.3zm-.7.7L2 13.3V2.7L7.3 8zm.7.7l5.3 5.3H2.7L8 8.7z' /></svg>} />
|
|
25
25
|
*/
|
|
26
26
|
export const ToggleSwitch = React.forwardRef((props, ref) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
props = { ...props };
|
|
31
|
-
delete props.icon;
|
|
32
|
-
}
|
|
33
|
-
const { disabled = false, labelPosition = 'right', label, className, style, size = 'default', ...rest } = props;
|
|
34
|
-
const inputElementRef = React.useRef(null);
|
|
35
|
-
const refs = useMergedRefs(inputElementRef, ref);
|
|
27
|
+
const { disabled = false, labelPosition = 'right', label, className, style, size = 'default', icon: iconProp, ...rest } = props;
|
|
28
|
+
// Disallow custom icon for small size, but keep the default checkmark when prop is not passed.
|
|
29
|
+
const shouldShowIcon = iconProp === undefined || (iconProp !== null && size !== 'small');
|
|
36
30
|
return (React.createElement(Box, { as: label ? 'label' : 'div', className: cx('iui-toggle-switch-wrapper', {
|
|
37
31
|
'iui-disabled': disabled,
|
|
38
32
|
'iui-label-on-right': label && labelPosition === 'right',
|
|
39
33
|
'iui-label-on-left': label && labelPosition === 'left',
|
|
40
34
|
}, className), "data-iui-size": size, style: style },
|
|
41
|
-
React.createElement(Box, { as: 'input', className: 'iui-toggle-switch', type: 'checkbox', role: 'switch', disabled: disabled, ref:
|
|
42
|
-
|
|
35
|
+
React.createElement(Box, { as: 'input', className: 'iui-toggle-switch', type: 'checkbox', role: 'switch', disabled: disabled, ref: ref, ...rest }),
|
|
36
|
+
shouldShowIcon && (React.createElement(Box, { as: 'span', className: 'iui-toggle-switch-icon', "aria-hidden": true }, iconProp || React.createElement(SvgCheckmark, null))),
|
|
43
37
|
label && (React.createElement(Box, { as: 'span', className: 'iui-toggle-switch-label' }, label))));
|
|
44
38
|
});
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
import type { PolymorphicForwardRefComponent } from '../utils/index.js';
|
|
2
|
+
type AnchorProps = {
|
|
3
|
+
/**
|
|
4
|
+
* Whether the anchor links to an external site.
|
|
5
|
+
*
|
|
6
|
+
* When true, there will be an icon added at the end of the anchor text. This is useful
|
|
7
|
+
* to indicate that the link will open in a new tab.
|
|
8
|
+
*
|
|
9
|
+
* Not all external links should open in a new tab, so this prop should be used with caution.
|
|
10
|
+
*/
|
|
11
|
+
isExternal?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the anchor should be underlined in its idle state.
|
|
14
|
+
*
|
|
15
|
+
* By default, the anchor is underlined only on hover, or when using a high-contrast theme.
|
|
16
|
+
*/
|
|
17
|
+
underline?: boolean;
|
|
18
|
+
};
|
|
1
19
|
/**
|
|
2
20
|
* A consistently styled anchor component.
|
|
3
21
|
*
|
|
@@ -7,9 +25,11 @@
|
|
|
7
25
|
* @example
|
|
8
26
|
* <Anchor href='/'>Home</Anchor>
|
|
9
27
|
* <Anchor href='/projects'>Projects</Anchor>
|
|
28
|
+
* <Anchor href='/help' underline>Help</Anchor>
|
|
10
29
|
*
|
|
11
30
|
* @example
|
|
12
31
|
* <Anchor as={Link} to='/'>Home</Anchor>
|
|
13
32
|
* <Anchor as='button' onClick={() => {}}>click me</Anchor>
|
|
14
33
|
*/
|
|
15
|
-
export declare const Anchor:
|
|
34
|
+
export declare const Anchor: PolymorphicForwardRefComponent<"a", AnchorProps>;
|
|
35
|
+
export {};
|
|
@@ -2,7 +2,10 @@
|
|
|
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
|
-
import
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import cx from 'classnames';
|
|
7
|
+
import { Box } from '../utils/index.js';
|
|
8
|
+
import { VisuallyHidden } from '../VisuallyHidden/VisuallyHidden.js';
|
|
6
9
|
/**
|
|
7
10
|
* A consistently styled anchor component.
|
|
8
11
|
*
|
|
@@ -12,9 +15,15 @@ import { polymorphic } from '../utils/index.js';
|
|
|
12
15
|
* @example
|
|
13
16
|
* <Anchor href='/'>Home</Anchor>
|
|
14
17
|
* <Anchor href='/projects'>Projects</Anchor>
|
|
18
|
+
* <Anchor href='/help' underline>Help</Anchor>
|
|
15
19
|
*
|
|
16
20
|
* @example
|
|
17
21
|
* <Anchor as={Link} to='/'>Home</Anchor>
|
|
18
22
|
* <Anchor as='button' onClick={() => {}}>click me</Anchor>
|
|
19
23
|
*/
|
|
20
|
-
export const Anchor =
|
|
24
|
+
export const Anchor = React.forwardRef((props, forwardedRef) => {
|
|
25
|
+
const { isExternal, underline, children, ...rest } = props;
|
|
26
|
+
return (React.createElement(Box, { as: 'a', "data-iui-underline": underline ? 'true' : undefined, ...rest, ref: forwardedRef, className: cx('iui-anchor', { 'iui-anchor-external': isExternal }, props.className) },
|
|
27
|
+
children,
|
|
28
|
+
props.target === '_blank' && (React.createElement(VisuallyHidden, null, " (opens in new tab)"))));
|
|
29
|
+
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import cx from 'classnames';
|
|
7
|
-
import { Box } from '../utils/
|
|
7
|
+
import { Box, ShadowRoot } from '../utils/index.js';
|
|
8
8
|
/**
|
|
9
9
|
* Hides content visually but keeps it still accessible to screen readers
|
|
10
10
|
* and other assistive technologies.
|
|
@@ -16,6 +16,22 @@ import { Box } from '../utils/components/Box.js';
|
|
|
16
16
|
* @see https://www.scottohara.me/blog/2017/04/14/inclusively-hidden.html
|
|
17
17
|
*/
|
|
18
18
|
export const VisuallyHidden = React.forwardRef((props, ref) => {
|
|
19
|
-
const { className, unhideOnFocus = true, ...rest } = props;
|
|
20
|
-
|
|
19
|
+
const { as: asProp = 'span', className, unhideOnFocus = true, children: childrenProp, ...rest } = props;
|
|
20
|
+
// ShadowRoot is not supported on all elements, so we only use it for few common ones.
|
|
21
|
+
const children = !['div', 'span', 'p'].includes(asProp) ? (childrenProp) : (React.createElement(React.Fragment, null,
|
|
22
|
+
React.createElement(ShadowRoot, { css: css },
|
|
23
|
+
React.createElement("slot", null)),
|
|
24
|
+
childrenProp));
|
|
25
|
+
return (React.createElement(Box, { as: asProp, className: cx('iui-visually-hidden', className), "data-iui-unhide-on-focus": unhideOnFocus ? true : undefined, ref: ref, ...rest }, children));
|
|
21
26
|
});
|
|
27
|
+
// ----------------------------------------------------------------------------
|
|
28
|
+
const css = /* css */ `
|
|
29
|
+
:host(:where(:not([data-iui-unhide-on-focus]:is(:focus-within, :active)))) {
|
|
30
|
+
clip-path: inset(50%) !important;
|
|
31
|
+
overflow: hidden !important;
|
|
32
|
+
position: absolute !important;
|
|
33
|
+
white-space: nowrap !important;
|
|
34
|
+
block-size: 1px !important;
|
|
35
|
+
inline-size: 1px !important;
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { PolymorphicForwardRefComponent } from '../props.js';
|
|
2
|
+
import type { IconProps } from '../../Icon/Icon.js';
|
|
3
|
+
import type { IconButtonProps } from '../../Buttons/IconButton.js';
|
|
2
4
|
export type InputFlexContainerProps = {
|
|
3
5
|
isDisabled?: boolean;
|
|
4
6
|
status?: 'positive' | 'warning' | 'negative';
|
|
@@ -9,3 +11,26 @@ export type InputFlexContainerProps = {
|
|
|
9
11
|
* @private
|
|
10
12
|
*/
|
|
11
13
|
export declare const InputFlexContainer: PolymorphicForwardRefComponent<"div", InputFlexContainerProps>;
|
|
14
|
+
/**
|
|
15
|
+
* Button inside InputFlexContainer that collapses the padding between the button and the input/textarea.
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
export declare const InputFlexContainerButton: PolymorphicForwardRefComponent<"button", Omit<IconButtonProps, "styleType"> & {
|
|
19
|
+
/**
|
|
20
|
+
* Style of the button.
|
|
21
|
+
* Use 'borderless' to hide outline.
|
|
22
|
+
* @default 'borderless'
|
|
23
|
+
*/
|
|
24
|
+
styleType?: IconButtonProps['styleType'];
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Icon inside InputFlexContainer that collapses the padding between the icon and the input/textarea.
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
export declare const InputFlexContainerIcon: PolymorphicForwardRefComponent<"span", Omit<IconProps, "padded"> & {
|
|
31
|
+
/**
|
|
32
|
+
* Option to add padding to the icon.
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
padded?: IconProps['padded'];
|
|
36
|
+
}>;
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import cx from 'classnames';
|
|
7
7
|
import { Box } from './Box.js';
|
|
8
|
+
import { Icon } from '../../Icon/Icon.js';
|
|
9
|
+
import { IconButton } from '../../Buttons/IconButton.js';
|
|
8
10
|
/**
|
|
9
11
|
* Utility component for input container with display flex abilities.
|
|
10
12
|
* @private
|
|
@@ -13,3 +15,19 @@ export const InputFlexContainer = React.forwardRef((props, ref) => {
|
|
|
13
15
|
const { isDisabled, status, children, className, size, style, ...rest } = props;
|
|
14
16
|
return (React.createElement(Box, { className: cx('iui-input-flex-container', className), "data-iui-status": status, "data-iui-size": size, "data-iui-disabled": isDisabled ? 'true' : undefined, ref: ref, style: style, ...rest }, children));
|
|
15
17
|
});
|
|
18
|
+
/**
|
|
19
|
+
* Button inside InputFlexContainer that collapses the padding between the button and the input/textarea.
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
export const InputFlexContainerButton = React.forwardRef((props, ref) => {
|
|
23
|
+
const { className, ...rest } = props;
|
|
24
|
+
return (React.createElement(IconButton, { ref: ref, className: cx('iui-input-flex-container-icon', className), styleType: 'borderless', ...rest }));
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Icon inside InputFlexContainer that collapses the padding between the icon and the input/textarea.
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
export const InputFlexContainerIcon = React.forwardRef((props, ref) => {
|
|
31
|
+
const { className, ...rest } = props;
|
|
32
|
+
return (React.createElement(Icon, { ref: ref, className: cx('iui-input-flex-container-icon', className), padded: true, ...rest }));
|
|
33
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import { Box } from './Box.js';
|
|
7
|
+
import { ShadowRoot } from './ShadowRoot.js';
|
|
8
|
+
/** @private */
|
|
9
|
+
export const LineClamp = React.forwardRef((props, forwardedRef) => {
|
|
10
|
+
const { lines, children, ...rest } = props;
|
|
11
|
+
return (React.createElement(Box, { ref: forwardedRef, ...rest, style: { '--_iui-line-clamp': lines, ...props.style } },
|
|
12
|
+
React.createElement(ShadowRoot, { css: css },
|
|
13
|
+
React.createElement("slot", null)),
|
|
14
|
+
children));
|
|
15
|
+
});
|
|
16
|
+
const css = /* css */ `
|
|
17
|
+
:host {
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
display: -webkit-box;
|
|
20
|
+
-webkit-line-clamp: var(--_iui-line-clamp, 3);
|
|
21
|
+
-webkit-box-orient: vertical;
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
@@ -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
|
+
});
|
|
@@ -6,5 +6,5 @@ import * as React from 'react';
|
|
|
6
6
|
import { Svg } from './Svg.js';
|
|
7
7
|
export const SvgStatusError = (props) => {
|
|
8
8
|
return (React.createElement(Svg, { ...props },
|
|
9
|
-
React.createElement("path", { d: '
|
|
9
|
+
React.createElement("path", { d: 'M9 12H7v-2h2v2Zm0-3H7V4h2v5Zm2.314-9H4.686L0 4.686v6.628L4.686 16h6.628L16 11.314V4.686L11.314 0Z' })));
|
|
10
10
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/itwinui-react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"author": "Bentley Systems",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -55,27 +55,6 @@
|
|
|
55
55
|
"ui",
|
|
56
56
|
"ux"
|
|
57
57
|
],
|
|
58
|
-
"scripts": {
|
|
59
|
-
"build": "yarn clean:build && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && tsc -p tsconfig.react-table.json && yarn build:styles && yarn build:post",
|
|
60
|
-
"build:styles": "vite build src/styles.js",
|
|
61
|
-
"build:watch": "concurrently \"tsc -p tsconfig.cjs.json --watch\" \"tsc -p tsconfig.esm.json --watch\"",
|
|
62
|
-
"build:post": "node ./scripts/postBuild.mjs",
|
|
63
|
-
"clean:build": "rimraf esm && rimraf cjs && rimraf react-table.d.ts",
|
|
64
|
-
"clean:coverage": "rimraf coverage",
|
|
65
|
-
"clean": "rimraf .turbo && yarn clean:coverage && yarn clean:build && rimraf node_modules",
|
|
66
|
-
"test": "yarn test:types && yarn test:unit",
|
|
67
|
-
"test:unit": "vitest run",
|
|
68
|
-
"test:unit:watch": "yarn test:unit --watch",
|
|
69
|
-
"test:types": "tsc -p tsconfig.test.json --noEmit",
|
|
70
|
-
"format": "prettier --config .prettierrc **/*.{tsx,ts,js} --ignore-path .gitignore --write",
|
|
71
|
-
"lint": "eslint \"**/*.{js,ts,tsx}\" --max-warnings=0",
|
|
72
|
-
"lint:fix": "yarn lint --fix && node ../../scripts/copyrightLinter.js --fix \"*/**/*.{js,ts,tsx}\"",
|
|
73
|
-
"dev": "yarn clean:build && concurrently \"yarn dev:esm\" \"yarn dev:cjs\" \"yarn build:styles --watch\" \"yarn dev:types\"",
|
|
74
|
-
"dev:esm": "swc src -d esm --watch",
|
|
75
|
-
"dev:cjs": "swc src -d cjs --watch -C module.type=commonjs",
|
|
76
|
-
"dev:types": "concurrently \"tsc -p tsconfig.cjs.json --emitDeclarationOnly --watch --preserveWatchOutput\" \"tsc -p tsconfig.esm.json --emitDeclarationOnly --watch --preserveWatchOutput\" \"tsc -p tsconfig.react-table.json --watch --preserveWatchOutput\"",
|
|
77
|
-
"dev:styles": "yarn build:styles --watch"
|
|
78
|
-
},
|
|
79
58
|
"dependencies": {
|
|
80
59
|
"@floating-ui/react": "^0.26.3",
|
|
81
60
|
"@itwin/itwinui-illustrations-react": "^2.1.0",
|
|
@@ -85,8 +64,6 @@
|
|
|
85
64
|
"tslib": "^2.6.0"
|
|
86
65
|
},
|
|
87
66
|
"devDependencies": {
|
|
88
|
-
"@itwin/itwinui-css": "^2.3.1",
|
|
89
|
-
"@itwin/itwinui-variables": "3.0.0",
|
|
90
67
|
"@swc/cli": "^0.1.62",
|
|
91
68
|
"@swc/core": "^1.3.68",
|
|
92
69
|
"@testing-library/jest-dom": "^6.3.0",
|
|
@@ -105,7 +82,9 @@
|
|
|
105
82
|
"react-dom": "^18.0.0",
|
|
106
83
|
"typescript": "~5.1.6",
|
|
107
84
|
"vite": "^5.0.12",
|
|
108
|
-
"vitest": "^1.2.1"
|
|
85
|
+
"vitest": "^1.2.1",
|
|
86
|
+
"@itwin/itwinui-css": "2.5.0",
|
|
87
|
+
"@itwin/itwinui-variables": "3.1.0"
|
|
109
88
|
},
|
|
110
89
|
"peerDependencies": {
|
|
111
90
|
"react": ">= 17.0.0 < 19.0.0",
|
|
@@ -123,5 +102,26 @@
|
|
|
123
102
|
"prettier": "configs/prettier-config",
|
|
124
103
|
"sideEffects": [
|
|
125
104
|
"styles.css"
|
|
126
|
-
]
|
|
127
|
-
|
|
105
|
+
],
|
|
106
|
+
"scripts": {
|
|
107
|
+
"build": "pnpm clean:build && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && tsc -p tsconfig.react-table.json && pnpm build:styles && pnpm build:post",
|
|
108
|
+
"build:styles": "vite build src/styles.js",
|
|
109
|
+
"build:watch": "concurrently \"tsc -p tsconfig.cjs.json --watch\" \"tsc -p tsconfig.esm.json --watch\"",
|
|
110
|
+
"build:post": "node ./scripts/postBuild.mjs",
|
|
111
|
+
"clean:build": "rimraf esm && rimraf cjs && rimraf react-table.d.ts",
|
|
112
|
+
"clean:coverage": "rimraf coverage",
|
|
113
|
+
"clean": "rimraf .turbo && pnpm clean:coverage && pnpm clean:build && rimraf node_modules",
|
|
114
|
+
"test": "pnpm test:types && pnpm test:unit",
|
|
115
|
+
"test:unit": "vitest run",
|
|
116
|
+
"test:unit:watch": "pnpm test:unit --watch",
|
|
117
|
+
"test:types": "tsc -p tsconfig.test.json --noEmit",
|
|
118
|
+
"format": "prettier --config .prettierrc **/*.{tsx,ts,js} --ignore-path .gitignore --write",
|
|
119
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\" --max-warnings=0",
|
|
120
|
+
"lint:fix": "pnpm lint --fix && node ../../scripts/copyrightLinter.js --fix \"*/**/*.{js,ts,tsx}\"",
|
|
121
|
+
"dev": "pnpm clean:build && concurrently \"pnpm dev:esm\" \"pnpm dev:cjs\" \"pnpm build:styles --watch\" \"pnpm dev:types\"",
|
|
122
|
+
"dev:esm": "swc src -d esm --watch",
|
|
123
|
+
"dev:cjs": "swc src -d cjs --watch -C module.type=commonjs",
|
|
124
|
+
"dev:types": "concurrently \"tsc -p tsconfig.cjs.json --emitDeclarationOnly --watch --preserveWatchOutput\" \"tsc -p tsconfig.esm.json --emitDeclarationOnly --watch --preserveWatchOutput\" \"tsc -p tsconfig.react-table.json --watch --preserveWatchOutput\"",
|
|
125
|
+
"dev:styles": "pnpm build:styles --watch"
|
|
126
|
+
}
|
|
127
|
+
}
|