Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FluidDatePicker): implement FluidDatePicker #12247

Merged
merged 20 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ad47c41
feat(FluidDatePicker): scaffold out initial react files
tw15egan Oct 5, 2022
43568cc
feat(FluidDatePicker): scaffold out more files
tw15egan Oct 5, 2022
6d1092b
style(FluidDatePicker): add more styles for FluidDatePicker
tw15egan Oct 6, 2022
1cbf3da
style(FluidDatePicker): add single invalid styles
tw15egan Oct 26, 2022
51a642a
style(FluidDatePicker): clean up invalid, warn states on all variants
tw15egan Oct 26, 2022
51d2602
fix(FluidDatePicker): always show range icon in fluid state
tw15egan Oct 26, 2022
6eb95a1
fix(FluidDatePicker): add invalid, warn icons to simple fluiddatepicker
tw15egan Oct 26, 2022
0a8d562
feat(FluidDatePicker): add invalid state to DatePicker
tw15egan Oct 26, 2022
262b4b8
test(FluidDatePicker): add e2e tests, update snapshots
tw15egan Oct 26, 2022
0abbc69
chore(FluidDatePicker): fix avt test name
tw15egan Oct 26, 2022
c5bae37
test(FluidDatePicker): add API tests
tw15egan Oct 27, 2022
f81465a
chore(FluidForm): add FluidDatePicker to FluidForm story, style fixes
tw15egan Oct 27, 2022
bcc1cd2
chore(storybook): fix playground, remove test examples
tw15egan Nov 1, 2022
1c0a88c
test(e2e): update id
tw15egan Nov 1, 2022
bce6c8d
Merge branch 'main' into fluid-datepicker
tw15egan Nov 3, 2022
75dfbb7
Update packages/react/src/components/FluidDatePicker/FluidDatePicker.…
tw15egan Nov 4, 2022
0c3a250
Update packages/react/src/components/FluidDatePicker/FluidDatePicker.…
tw15egan Nov 4, 2022
9a981f1
Update packages/react/src/components/FluidDatePicker/FluidDatePicker.…
tw15egan Nov 4, 2022
7965bc7
Merge branch 'main' into fluid-datepicker
tw15egan Nov 4, 2022
5675d84
Merge branch 'main' into fluid-datepicker
kodiakhq[bot] Nov 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions e2e/components/FluidDatePicker/FluidDatePicker-test.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* 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.
*/

'use strict';

const { expect, test } = require('@playwright/test');
const { themes } = require('../../test-utils/env');
const { snapshotStory, visitStory } = require('../../test-utils/storybook');

test.describe('FluidDatePicker', () => {
themes.forEach((theme) => {
test.describe(theme, () => {
test('fluid date picker (range) @vrt', async ({ page }) => {
await snapshotStory(page, {
component: 'FluidDatePicker',
id: 'experimental-unstable-fluiddatepicker--range-with-calendar',
theme,
});
});

test('fluid date picker (single) @vrt', async ({ page }) => {
await snapshotStory(page, {
component: 'FluidDatePicker',
id: 'experimental-unstable-fluiddatepicker--single',
theme,
});
});

test('fluid date picker (simple) @vrt', async ({ page }) => {
await snapshotStory(page, {
component: 'FluidDatePicker',
id: 'experimental-unstable-fluiddatepicker--simple',
theme,
});
});
});
});

test('accessibility-checker @avt', async ({ page }) => {
await visitStory(page, {
component: 'FluidDatePicker',
id: 'experimental-unstable-fluiddatepicker--range-with-calendar',
globals: {
theme: 'white',
},
});
await visitStory(page, {
component: 'FluidDatePicker',
id: 'experimental-unstable-fluiddatepicker--single',
globals: {
theme: 'white',
},
});
await visitStory(page, {
component: 'FluidDatePicker',
id: 'experimental-unstable-fluiddatepicker--simple',
globals: {
theme: 'white',
},
});
await expect(page).toHaveNoACViolations('FluidDatePicker');
});
});
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-date-picker/fluid-date-picker';
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-date-picker';
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-date-picker/fluid-date-picker';
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-date-picker';
40 changes: 40 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2367,6 +2367,12 @@ Map {
"inline": Object {
"type": "bool",
},
"invalid": Object {
"type": "bool",
},
"invalidText": Object {
"type": "node",
},
"light": [Function],
"locale": Object {
"args": Array [
Expand Down Expand Up @@ -2501,6 +2507,12 @@ Map {
],
"type": "oneOfType",
},
"warn": Object {
"type": "bool",
},
"warnText": Object {
"type": "node",
},
},
"render": [Function],
},
Expand Down Expand Up @@ -9400,6 +9412,34 @@ Map {
},
},
},
"unstable__FluidDatePicker" => Object {
"$$typeof": Symbol(react.forward_ref),
"propTypes": Object {
"children": Object {
"type": "node",
},
"className": Object {
"type": "string",
},
"invalid": Object {
"type": "bool",
},
"invalidText": Object {
"type": "node",
},
"warn": Object {
"type": "bool",
},
"warnText": Object {
"type": "node",
},
},
"render": [Function],
},
"unstable__FluidDatePickerInput" => Object {
"$$typeof": Symbol(react.forward_ref),
"render": [Function],
},
"unstable__FluidDropdown" => Object {
"$$typeof": Symbol(react.forward_ref),
"propTypes": Object {
Expand Down
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-date-picker/fluid-date-picker';
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-date-picker';
2 changes: 2 additions & 0 deletions packages/react/src/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ describe('Carbon Components React', () => {
"unstable_TextDirection",
"unstable__FluidComboBox",
"unstable__FluidComboBoxSkeleton",
"unstable__FluidDatePicker",
"unstable__FluidDatePickerInput",
"unstable__FluidDropdown",
"unstable__FluidDropdownSkeleton",
"unstable__FluidMultiSelect",
Expand Down
57 changes: 56 additions & 1 deletion packages/react/src/components/DatePicker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import PropTypes from 'prop-types';
import React, { useEffect, useRef } from 'react';
import React, { useContext, useEffect, useRef } from 'react';
import cx from 'classnames';
import flatpickr from 'flatpickr';
import l10n from 'flatpickr/dist/l10n/index';
Expand All @@ -18,6 +18,8 @@ import deprecate from '../../prop-types/deprecate';
import { match, keys } from '../../internal/keyboard';
import { usePrefix } from '../../internal/usePrefix';
import { useSavedCallback } from '../../internal/useSavedCallback';
import { FormContext } from '../FluidForm';
import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';

// Weekdays shorthand for english locale
l10n.en.weekdays.shorthand.forEach((_day, index) => {
Expand Down Expand Up @@ -187,6 +189,10 @@ const DatePicker = React.forwardRef(function DatePicker(
disable,
enable,
inline,
invalid,
invalidText,
warn,
warnText,
light = false,
locale = 'en',
maxDate,
Expand All @@ -201,6 +207,7 @@ const DatePicker = React.forwardRef(function DatePicker(
ref
) {
const prefix = usePrefix();
const { isFluid } = useContext(FormContext);
const startInputField = useRef(null);
const endInputField = useRef(null);
const calendarRef = useRef(null);
Expand Down Expand Up @@ -467,9 +474,37 @@ const DatePicker = React.forwardRef(function DatePicker(
}
}, [value, prefix]);

let fluidError;
if (isFluid) {
if (invalid) {
fluidError = (
<>
<WarningFilled
className={`${prefix}--date-picker__icon ${prefix}--date-picker__icon--invalid`}
/>
<hr className={`${prefix}--date-picker__divider`} />
<div className={`${prefix}--form-requirement`}>{invalidText}</div>
</>
);
}

if (warn && !invalid) {
fluidError = (
<>
<WarningAltFilled
className={`${prefix}--date-picker__icon ${prefix}--date-picker__icon--warn`}
/>
<hr className={`${prefix}--date-picker__divider`} />
<div className={`${prefix}--form-requirement`}>{warnText}</div>
</>
);
}
}

return (
<div className={wrapperClasses} ref={ref} {...rest}>
<div className={datePickerClasses}>{childrenWithProps}</div>
{fluidError}
</div>
);
});
Expand Down Expand Up @@ -530,6 +565,16 @@ DatePicker.propTypes = {
*/
inline: PropTypes.bool,

/**
* Specify whether or not the control is invalid (Fluid only)
*/
invalid: PropTypes.bool,

/**
* Provide the text that is displayed when the control is in error state (Fluid Only)
*/
invalidText: PropTypes.node,

/**
* `true` to use the light version.
*/
Expand Down Expand Up @@ -654,6 +699,16 @@ DatePicker.propTypes = {
PropTypes.object,
PropTypes.number,
]),

/**
* Specify whether the control is currently in warning state (Fluid only)
*/
warn: PropTypes.bool,

/**
* Provide the text that is displayed when the control is in warning state (Fluid only)
*/
warnText: PropTypes.node,
};

export default DatePicker;
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import { Calendar, WarningFilled, WarningAltFilled } from '@carbon/icons-react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import React, { useContext } from 'react';
import { usePrefix } from '../../internal/usePrefix';
import { FormContext } from '../FluidForm';

const DatePickerInput = React.forwardRef(function DatePickerInput(props, ref) {
const {
Expand All @@ -32,6 +33,7 @@ const DatePickerInput = React.forwardRef(function DatePickerInput(props, ref) {
...rest
} = props;
const prefix = usePrefix();
const { isFluid } = useContext(FormContext);
const datePickerInputProps = {
id,
onChange: (event) => {
Expand Down Expand Up @@ -62,9 +64,12 @@ const DatePickerInput = React.forwardRef(function DatePickerInput(props, ref) {
const inputClasses = cx(`${prefix}--date-picker__input`, {
[`${prefix}--date-picker__input--${size}`]: size,
[`${prefix}--date-picker__input--invalid`]: invalid,
[`${prefix}--date-picker__input--warn`]: warn,
});
const containerClasses = cx(`${prefix}--date-picker-container`, {
[`${prefix}--date-picker--nolabel`]: !labelText,
[`${prefix}--date-picker--fluid--invalid`]: isFluid && invalid,
[`${prefix}--date-picker--fluid--warn`]: isFluid && warn,
});

const input = invalid ? (
Expand Down Expand Up @@ -95,16 +100,25 @@ const DatePickerInput = React.forwardRef(function DatePickerInput(props, ref) {
)}
<div className={wrapperClasses}>
{input}
{isFluid && <DatePickerIcon datePickerType={datePickerType} />}
<DatePickerIcon
datePickerType={datePickerType}
invalid={invalid}
warn={warn}
/>
</div>
{invalid && (
<div className={`${prefix}--form-requirement`}>{invalidText}</div>
<>
{isFluid && <hr className={`${prefix}--date-picker__divider`} />}
<div className={`${prefix}--form-requirement`}>{invalidText}</div>
</>
)}
{warn && (
<>
{isFluid && <hr className={`${prefix}--date-picker__divider`} />}
<div className={`${prefix}--form-requirement`}>{warnText}</div>
</>
)}
{warn && <div className={`${prefix}--form-requirement`}>{warnText}</div>}
{helperText && <div className={helperTextClasses}>{helperText}</div>}
</div>
);
Expand Down Expand Up @@ -211,9 +225,12 @@ DatePickerInput.propTypes = {

function DatePickerIcon({ datePickerType, invalid, warn }) {
const prefix = usePrefix();
const { isFluid } = useContext(FormContext);

if (datePickerType === 'simple' && !invalid && !warn) {
return null;
if (!isFluid) {
return null;
}
}

if (invalid) {
Expand Down
Loading