-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FluidTimePicker): add
FluidTimePicker
variant (#12603)
* feat(FluidTimePicker): scaffold out react files * feat(FluidTimePicker): scaffold sass files, fix FluidSelect outline * feat(FluidTimePicker): implement error state * style(FluidTimePicker): work on invalid styles * style(FluidTimePicker): add warning styles, fix playground story * test(FluidTimePicker): update tests * refactor(FluidTimePicker): remove single element invalid styles * test(FluidTimePicker): update tests, snapshots * style(Fluid): update Fluid skeleton styles * test(e2e): add e2e tests for FluidTimePicker * style(FluidTimePicker): fix invalid state * chore(storybook): clean up storybook a11y issues Co-authored-by: Alison Joseph <alison.joseph@us.ibm.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
43e6216
commit b77359f
Showing
28 changed files
with
1,034 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const { expect, test } = require('@playwright/test'); | ||
const { themes } = require('../../test-utils/env'); | ||
const { snapshotStory, visitStory } = require('../../test-utils/storybook'); | ||
|
||
test.describe('FluidTimePicker', () => { | ||
themes.forEach((theme) => { | ||
test.describe(theme, () => { | ||
test('fluid text input @vrt', async ({ page }) => { | ||
await snapshotStory(page, { | ||
component: 'FluidTimePicker', | ||
id: 'experimental-unstable-fluidtimepicker--default', | ||
theme, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
test('accessibility-checker @avt', async ({ page }) => { | ||
await visitStory(page, { | ||
component: 'FluidTimePicker', | ||
id: 'experimental-unstable-fluidtimepicker--default', | ||
globals: { | ||
theme: 'white', | ||
}, | ||
}); | ||
await expect(page).toHaveNoACViolations('FluidTimePicker'); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/carbon-components-react/scss/components/fluid-time-picker/_fluid-time-picker.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Code generated by carbon-components-react. DO NOT EDIT. | ||
// | ||
// Copyright IBM Corp. 2018, 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. | ||
// | ||
|
||
@forward '@carbon/styles/scss/components/fluid-time-picker/fluid-time-picker'; |
9 changes: 9 additions & 0 deletions
9
packages/carbon-components-react/scss/components/fluid-time-picker/_index.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Code generated by carbon-components-react. DO NOT EDIT. | ||
// | ||
// Copyright IBM Corp. 2018, 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. | ||
// | ||
|
||
@forward '@carbon/styles/scss/components/fluid-time-picker'; |
9 changes: 9 additions & 0 deletions
9
packages/carbon-components/scss/components/fluid-time-picker/_fluid-time-picker.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Code generated by carbon-components. DO NOT EDIT. | ||
// | ||
// Copyright IBM Corp. 2018, 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. | ||
// | ||
|
||
@forward '@carbon/styles/scss/components/fluid-time-picker/fluid-time-picker'; |
9 changes: 9 additions & 0 deletions
9
packages/carbon-components/scss/components/fluid-time-picker/_index.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Code generated by carbon-components. DO NOT EDIT. | ||
// | ||
// Copyright IBM Corp. 2018, 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. | ||
// | ||
|
||
@forward '@carbon/styles/scss/components/fluid-time-picker'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/react/scss/components/fluid-time-picker/_fluid-time-picker.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Code generated by @carbon/react. DO NOT EDIT. | ||
// | ||
// Copyright IBM Corp. 2018, 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. | ||
// | ||
|
||
@forward '@carbon/styles/scss/components/fluid-time-picker/fluid-time-picker'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Code generated by @carbon/react. DO NOT EDIT. | ||
// | ||
// Copyright IBM Corp. 2018, 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. | ||
// | ||
|
||
@forward '@carbon/styles/scss/components/fluid-time-picker'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/react/src/components/FluidTimePicker/FluidTimePicker.Skeleton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright IBM Corp. 2022 | ||
* | ||
* 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 PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
import { usePrefix } from '../../internal/usePrefix'; | ||
import { FluidTextInputSkeleton } from '../FluidTextInput'; | ||
import { FluidSelectSkeleton } from '../FluidSelect'; | ||
|
||
const FluidTimePickerSkeleton = ({ className, isOnlyTwo, ...rest }) => { | ||
const prefix = usePrefix(); | ||
const wrapperClasses = cx( | ||
className, | ||
`${prefix}--time-picker--fluid--skeleton`, | ||
{ | ||
[`${prefix}--time-picker--equal-width`]: isOnlyTwo, | ||
} | ||
); | ||
|
||
return ( | ||
<div className={wrapperClasses} {...rest}> | ||
<FluidTextInputSkeleton /> | ||
<FluidSelectSkeleton /> | ||
{!isOnlyTwo ? <FluidSelectSkeleton /> : null} | ||
</div> | ||
); | ||
}; | ||
|
||
FluidTimePickerSkeleton.propTypes = { | ||
/** | ||
* Specify an optional className to add. | ||
*/ | ||
className: PropTypes.string, | ||
|
||
/** | ||
* Specify if there are only two TimePicker elements | ||
*/ | ||
isOnlyTwo: PropTypes.bool, | ||
}; | ||
|
||
export default FluidTimePickerSkeleton; |
121 changes: 121 additions & 0 deletions
121
packages/react/src/components/FluidTimePicker/FluidTimePicker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/** | ||
* Copyright IBM Corp. 2022 | ||
* | ||
* 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 PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import classnames from 'classnames'; | ||
import FluidTextInput from '../FluidTextInput'; | ||
import { usePrefix } from '../../internal/usePrefix'; | ||
import { WarningFilled, WarningAltFilled } from '@carbon/icons-react'; | ||
|
||
const FluidTimePicker = React.forwardRef(function FluidTimePicker( | ||
{ | ||
className, | ||
children, | ||
disabled, | ||
invalid, | ||
invalidText, | ||
warn, | ||
warnText, | ||
...other | ||
}, | ||
ref | ||
) { | ||
const prefix = usePrefix(); | ||
|
||
const classNames = classnames(className, { | ||
[`${prefix}--time-picker--fluid`]: true, | ||
[`${prefix}--time-picker--equal-width`]: children?.length !== 2, | ||
[`${prefix}--time-picker--fluid--disabled`]: disabled, | ||
[`${prefix}--time-picker--fluid--invalid`]: invalid, | ||
[`${prefix}--time-picker--fluid--warning`]: warn, | ||
}); | ||
|
||
const errorText = () => { | ||
if (invalid) { | ||
return invalidText; | ||
} | ||
if (warn) { | ||
return warnText; | ||
} | ||
}; | ||
|
||
const error = invalid || warn; | ||
|
||
return ( | ||
<div className={classNames}> | ||
<div className={`${prefix}--time-picker--fluid__wrapper`}> | ||
<div className={`${prefix}--time-picker__input`}> | ||
<FluidTextInput disabled={disabled} ref={ref} {...other} /> | ||
</div> | ||
{disabled | ||
? React.Children.toArray(children).map((child) => { | ||
return React.cloneElement(child, { disabled }); | ||
}) | ||
: children} | ||
</div> | ||
{error && <hr className={`${prefix}--time-picker__divider`} />} | ||
{error && ( | ||
<div className={`${prefix}--form-requirement`}>{errorText()}</div> | ||
)} | ||
{error && invalid ? ( | ||
<WarningFilled | ||
className={`${prefix}--time-picker__icon ${prefix}--time-picker__icon--invalid`} | ||
/> | ||
) : ( | ||
<WarningAltFilled | ||
className={`${prefix}--time-picker__icon ${prefix}--time-picker__icon--warn`} | ||
/> | ||
)} | ||
</div> | ||
); | ||
}); | ||
|
||
FluidTimePicker.propTypes = { | ||
/** | ||
* The child node(s) | ||
*/ | ||
children: PropTypes.node, | ||
|
||
/** | ||
* Specify an optional className to be applied to the outer FluidTimePicker wrapper | ||
*/ | ||
className: PropTypes.string, | ||
|
||
/** | ||
* Specify whether the `<input>` should be disabled | ||
*/ | ||
disabled: PropTypes.bool, | ||
|
||
/** | ||
* Specify whether or not the control is invalid | ||
*/ | ||
invalid: PropTypes.bool, | ||
|
||
/** | ||
* Provide the text that is displayed when the control is in error state | ||
*/ | ||
invalidText: PropTypes.node, | ||
|
||
/** | ||
* Provide the text that will be read by a screen reader when visiting this | ||
* control | ||
*/ | ||
labelText: PropTypes.node.isRequired, | ||
|
||
/** | ||
* Specify whether the control is currently in warning state | ||
*/ | ||
warn: PropTypes.bool, | ||
|
||
/** | ||
* Provide the text that is displayed when the control is in warning state | ||
*/ | ||
warnText: PropTypes.node, | ||
}; | ||
|
||
export default FluidTimePicker; |
Oops, something went wrong.