From cd33ffa64f59221e8b53d020eaad012075684464 Mon Sep 17 00:00:00 2001 From: Taylor Jones Date: Mon, 13 Dec 2021 12:21:58 -0600 Subject: [PATCH 1/3] Revert "docs(checkbox): add storybook docs for onClick (#10130)" (#10266) This reverts commit 46eded4832a7e8878ba08e239902d866bc4a785d. Co-authored-by: Josefina Mancilla <32556167+jnm2377@users.noreply.github.com> --- .../react/src/components/Checkbox/Checkbox.mdx | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/packages/react/src/components/Checkbox/Checkbox.mdx b/packages/react/src/components/Checkbox/Checkbox.mdx index 5adba1226fcb..26d68a94e3f1 100644 --- a/packages/react/src/components/Checkbox/Checkbox.mdx +++ b/packages/react/src/components/Checkbox/Checkbox.mdx @@ -91,23 +91,6 @@ event. {}} labelText={`Checkbox label`} id="checkbox-label-2" /> ``` -### Checkbox onClick - -You can use the `onClick` prop to pass in a custom function for event handling. -This event can be used to control click event bubbling without having to -implement your own wrapping element/component. It receives the dom event as its -only argument. - -`onClick` is placed on the wrapping `div` containing both the `input` and -`label`. As such, this will be called twice for every click - once for the -input, a second time for the label. Due to this, `onClick` should not be used to -catch state updates when using Checkbox as a controlled component. - -```jsx -{}} labelText={`Checkbox label`} id="checkbox-label-1" /> -{}} labelText={`Checkbox label`} id="checkbox-label-2" /> -``` - ## Feedback Help us improve this component by providing feedback, asking questions on Slack, From ddaadaad1e95dd44dc34b5c16268437568123793 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Mon, 13 Dec 2021 12:46:52 -0600 Subject: [PATCH 2/3] chore: update codeowners to point to the correct SVG files (#10270) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- CODEOWNERS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index 370a9b256363..d723394cbf6c 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -2,8 +2,8 @@ * @carbon-design-system/developers-system # Core icons and pictograms -/packages/icons/svg/ @laurenmrice @conradennis @dudley-ibm @carbon-design-system/developers-system -/packages/pictograms/svg/ @laurenmrice @conradennis @dudley-ibm @carbon-design-system/developers-system +/packages/icons/src/svg/ @laurenmrice @conradennis @dudley-ibm @carbon-design-system/developers-system +/packages/pictograms/src/svg/ @laurenmrice @conradennis @dudley-ibm @carbon-design-system/developers-system # Angular icons /packages/icons-angular/ @cal-smith @carbon-design-system/developers-system From 8b01d69dfcd94155b764ad301f45ec60ffe05bcb Mon Sep 17 00:00:00 2001 From: Josh Black Date: Mon, 13 Dec 2021 16:41:13 -0600 Subject: [PATCH 3/3] refactor(number-input): refactor to functional component (#10257) * refactor(number-input): refactor to functional component * test(number-input): update tests to work with forwardRef * docs: revert v11 react migration changes * test(react): update number input test Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../NumberInput/next/NumberInput.js | 456 +++++++++++++++++ .../NumberInput/next/NumberInput.stories.js | 114 +++-- .../next/__tests__/NumberInput-test.js | 477 ++++++++++++++++++ .../src/components/NumberInput/next/index.js | 8 + 4 files changed, 1024 insertions(+), 31 deletions(-) create mode 100644 packages/react/src/components/NumberInput/next/NumberInput.js create mode 100644 packages/react/src/components/NumberInput/next/__tests__/NumberInput-test.js create mode 100644 packages/react/src/components/NumberInput/next/index.js diff --git a/packages/react/src/components/NumberInput/next/NumberInput.js b/packages/react/src/components/NumberInput/next/NumberInput.js new file mode 100644 index 000000000000..7a95632f9bd7 --- /dev/null +++ b/packages/react/src/components/NumberInput/next/NumberInput.js @@ -0,0 +1,456 @@ +/** + * Copyright IBM Corp. 2016, 2018 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { Add16, Subtract16 } from '@carbon/icons-react'; +import cx from 'classnames'; +import PropTypes from 'prop-types'; +import React, { useRef, useState } from 'react'; +import { useFeatureFlag } from '../../FeatureFlags'; +import { useMergedRefs } from '../../../internal/useMergedRefs'; +import { useNormalizedInputProps as normalize } from '../../../internal/useNormalizedInputProps'; +import { usePrefix } from '../../../internal/usePrefix'; +import deprecate from '../../../prop-types/deprecate'; + +export const translationIds = { + 'increment.number': 'increment.number', + 'decrement.number': 'decrement.number', +}; + +const defaultTranslations = { + [translationIds['increment.number']]: 'Increment number', + [translationIds['decrement.number']]: 'Decrement number', +}; + +const NumberInput = React.forwardRef(function NumberInput(props, forwardRef) { + const enabled = useFeatureFlag('enable-v11-release'); + const { + allowEmpty = false, + className: customClassName, + disabled = false, + defaultValue, + helperText = '', + hideLabel = false, + hideSteppers, + iconDescription = enabled ? undefined : 'choose a number', + id, + label, + invalid = false, + invalidText = enabled ? undefined : 'Provide invalidText', + isMobile, + light = false, + max, + min, + onChange, + onClick, + readOnly, + size, + step = 1, + translateWithId: t = (id) => defaultTranslations[id], + warn = false, + warnText = '', + value: controlledValue, + ...rest + } = props; + const prefix = usePrefix(); + const [value, setValue] = useState(() => { + if (controlledValue !== undefined) { + return controlledValue; + } + if (defaultValue !== undefined) { + return defaultValue; + } + return 0; + }); + const [prevControlledValue, setPrevControlledValue] = useState( + controlledValue + ); + const inputRef = useRef(null); + const ref = useMergedRefs([forwardRef, inputRef]); + const numberInputClasses = cx({ + [`${prefix}--number`]: true, + [`${prefix}--number--helpertext`]: true, + [`${prefix}--number--readonly`]: readOnly, + [`${prefix}--number--light`]: light, + [`${prefix}--number--nolabel`]: hideLabel, + [`${prefix}--number--nosteppers`]: hideSteppers, + [`${prefix}--number--mobile`]: isMobile, + [`${prefix}--number--${size}`]: size, + [customClassName]: !enabled, + }); + const isInputValid = getInputValidity({ + allowEmpty, + invalid, + value, + max, + min, + }); + const normalizedProps = normalize({ + id, + readOnly, + disabled, + invalid: !isInputValid, + invalidText, + warn, + warnText, + }); + const [incrementNumLabel, decrementNumLabel] = [ + t('increment.number'), + t('decrement.number'), + ]; + const wrapperClasses = cx(`${prefix}--number__input-wrapper`, { + [`${prefix}--number__input-wrapper--warning`]: normalizedProps.warn, + }); + const iconClasses = cx({ + [`${prefix}--number__invalid`]: + normalizedProps.invalid || normalizedProps.warn, + [`${prefix}--number__invalid--warning`]: normalizedProps.warn, + [`${prefix}--number__readonly-icon`]: readOnly, + }); + + if (controlledValue !== prevControlledValue) { + setValue(controlledValue); + setPrevControlledValue(controlledValue); + } + + let ariaDescribedBy = null; + if (normalizedProps.invalid) { + ariaDescribedBy = normalizedProps.invalidId; + } + if (normalizedProps.warn) { + ariaDescribedBy = normalizedProps.warnId; + } + + function handleOnChange(event) { + if (disabled) { + return; + } + + const state = { + value: event.target.value, + direction: value < event.target.value ? 'up' : 'down', + }; + setValue(state.value); + + if (onChange) { + onChange(event, state); + } + } + + return ( +
+
+