diff --git a/packages/react-components/src/components/AutoComplete/AutoComplete.stories.tsx b/packages/react-components/src/components/AutoComplete/AutoComplete.stories.tsx index bdac8785e..1501fd231 100644 --- a/packages/react-components/src/components/AutoComplete/AutoComplete.stories.tsx +++ b/packages/react-components/src/components/AutoComplete/AutoComplete.stories.tsx @@ -126,6 +126,15 @@ export const Examples = (): React.ReactElement => { + + + + ); }; diff --git a/packages/react-components/src/components/AutoComplete/AutoComplete.tsx b/packages/react-components/src/components/AutoComplete/AutoComplete.tsx index 4e25a1fba..ecc042da5 100644 --- a/packages/react-components/src/components/AutoComplete/AutoComplete.tsx +++ b/packages/react-components/src/components/AutoComplete/AutoComplete.tsx @@ -2,12 +2,14 @@ import * as React from 'react'; import { FloatingNode, FloatingPortal } from '@floating-ui/react'; +import { useReadOnlyFormFieldContext } from '../../providers/ReadOnlyFormFieldProvider'; import noop from '../../utils/noop'; import { Input } from '../Input'; import { IPickerListItem, PickerList } from '../Picker'; import { DEFAULT_LIST_HEIGHT, MIN_LIST_HEIGHT } from '../Picker/constants'; import { useFloatingPicker } from '../Picker/hooks/useFloatingPicker'; import { usePickerItems } from '../Picker/hooks/usePickerItems'; +import { ReadOnlyText } from '../ReadOnlyText'; import { areAllOptionsStrings, @@ -44,11 +46,14 @@ export const AutoComplete = React.forwardRef< single, alwaysShowAllOptions, hideIfExactMatch = true, + noDataFallbackText = 'No data', ...inputProps }, ref ) => { const inputRef = React.useRef(null); + const { readOnly: readOnlyContext } = useReadOnlyFormFieldContext(); + const computedReadOnly = readOnlyContext || readOnly; React.useImperativeHandle(ref, () => inputRef.current!, []); @@ -158,6 +163,15 @@ export const AutoComplete = React.forwardRef< floatingStrategy, }); + if (computedReadOnly) { + return ( + + ); + } + return (
{ single?: boolean; /** If true, the option list will be hidden if there is only one option and it is an exact match to the input value. */ hideIfExactMatch?: boolean; + /** + * Set the text to display with read-only state when there is no data. Default to 'No data' + */ + noDataFallbackText?: string; } diff --git a/packages/react-components/src/components/Checkbox/Checkbox.module.scss b/packages/react-components/src/components/Checkbox/Checkbox.module.scss index e54e7ee46..ec3e80440 100644 --- a/packages/react-components/src/components/Checkbox/Checkbox.module.scss +++ b/packages/react-components/src/components/Checkbox/Checkbox.module.scss @@ -98,6 +98,27 @@ } } + &--read-only { + .checkbox { + &__input { + border-color: var(--border-basic-secondary); + background-color: var(--surface-primary-default); + + &::after { + background-color: var(--content-basic-primary); + } + } + + &__label, + &__input, + &__helper, + &__text { + cursor: default; + pointer-events: none; + } + } + } + &--selected { &:hover { .checkbox__input:checked + .checkbox__square { diff --git a/packages/react-components/src/components/Checkbox/Checkbox.stories.tsx b/packages/react-components/src/components/Checkbox/Checkbox.stories.tsx index 3dcb0c7c1..9f8fa6a84 100644 --- a/packages/react-components/src/components/Checkbox/Checkbox.stories.tsx +++ b/packages/react-components/src/components/Checkbox/Checkbox.stories.tsx @@ -38,6 +38,9 @@ export const States = (): React.ReactElement => ( Checkbox label + + Checkbox label + @@ -46,6 +49,9 @@ export const States = (): React.ReactElement => ( Checkbox label + + Checkbox label + ( > Checkbox label + + Checkbox label + ); diff --git a/packages/react-components/src/components/Checkbox/Checkbox.tsx b/packages/react-components/src/components/Checkbox/Checkbox.tsx index 5d294663a..2b8473625 100644 --- a/packages/react-components/src/components/Checkbox/Checkbox.tsx +++ b/packages/react-components/src/components/Checkbox/Checkbox.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import cx from 'clsx'; +import { useReadOnlyFormFieldContext } from '../../providers/ReadOnlyFormFieldProvider'; import { FieldDescription } from '../FieldDescription'; import { Text } from '../Typography'; @@ -12,6 +13,10 @@ export interface CheckboxProps extends React.HTMLAttributes { * Specify whether the checkbox should be disabled */ disabled?: boolean; + /** + * Specify whether the checkbox should be read only + */ + readOnly?: boolean; /** * Specify whether the checkbox should be checked */ @@ -41,12 +46,16 @@ export const Checkbox = React.forwardRef( }, ref ) => { + const { readOnly } = useReadOnlyFormFieldContext(); + const computedReadOnly = readOnly || restInputProps.readOnly; + return (