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

[Feature] TimeInput #782

Merged
merged 25 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1f6be16
WIP: TimeInput
riitasointi Aug 29, 2023
251c2f8
TimeInput: Add onChange, onKeyDown and onBlur handlers
riitasointi Aug 31, 2023
cf7c7dc
TimeInput: Remove an example from md file for now
riitasointi Aug 31, 2023
e5a2752
TImeInput: Change separator from : to .
riitasointi Sep 4, 2023
0f465b4
TimeInput: Change to one field format
riitasointi Sep 14, 2023
fe8a8b3
TimeInput autocomplete and style fixes
riitasointi Sep 14, 2023
272cc83
TimeInput: Add some more logic and styles
riitasointi Sep 27, 2023
b4bb0e4
TimeInput: Some more logic and docs
riitasointi Oct 3, 2023
4cdaa91
TimeInput: Add margin props support and adjust autocomplete logic
riitasointi Oct 3, 2023
2f66eb9
TimeInput: Remove visualPlaceholder prop
riitasointi Oct 3, 2023
b06f902
TimeInput: Add tests
riitasointi Oct 3, 2023
69b93f5
TimeInput: Add debounce test and docs
riitasointi Oct 5, 2023
ecbf0f0
TimeInput: Set explicit height
riitasointi Oct 9, 2023
f1dda8c
TimeInput & TextInput: Fix hintText prop description
riitasointi Oct 9, 2023
50235c3
TimeInput: Refactor 1 & 2 digit autocomplete logic
riitasointi Oct 9, 2023
cc22a11
TimeInput: Remove redundant props
riitasointi Oct 9, 2023
53b5342
TimeInput: Adjust docs
riitasointi Oct 9, 2023
6dafc31
TextInput: Remove hardcoded placeholder and add back visualPlaceholde…
riitasointi Oct 11, 2023
9862d79
Update TimeInput.test.tsx.snap
riitasointi Oct 11, 2023
9657730
TimeInput: Move autocomplete logic to helpers and export it from the …
riitasointi Oct 11, 2023
899f385
TimeInput: Add controlled autocompletion example to docs
riitasointi Oct 11, 2023
ed5446f
TimeInput: Add further check to autocompleteTimeString and adjust exa…
riitasointi Oct 12, 2023
534a6fe
TimeInput: Make sure dots are escaped in regexps
riitasointi Oct 12, 2023
6178bd2
DateInput: Add onDatePickerButtonBlur() prop
riitasointi Oct 16, 2023
af70f58
Remove old team members from CODEOWNERS
riitasointi Oct 16, 2023
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
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @LJKaski @riitasointi @Riippi @jenkrisu
* @LJKaski @riitasointi
1 change: 1 addition & 0 deletions .styleguidist/spacingprops.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ The following components support margin props
- Text
- Textarea
- TextInput
- TimeInput
- Toast
- ToggleButton
- ToggleInput
Expand Down
1 change: 1 addition & 0 deletions .styleguidist/styleguidist.sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const singularComponents = [
'Notification',
'Toast',
['Form', 'TextInput'],
['Form', 'TimeInput'],
['Form', 'SearchInput'],
['Form', 'Textarea'],
['Form', 'DateInput'],
Expand Down
16 changes: 16 additions & 0 deletions src/core/Form/DateInput/DateInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ describe('callbacks', () => {
expect(mockOnBlur).toBeCalledTimes(1);
});
});

describe('onDatePickerButtonBlur', () => {
it('calls onBlur when date picker button is blurred', () => {
const mockOnBlur = jest.fn();
const { getByRole } = render(
<DateInput
labelText="Date"
datePickerEnabled
onDatePickerButtonBlur={mockOnBlur}
/>,
);
fireEvent.focus(getByRole('button'));
fireEvent.blur(getByRole('button'));
expect(mockOnBlur).toBeCalledTimes(1);
});
});
});

describe('props', () => {
Expand Down
10 changes: 10 additions & 0 deletions src/core/Form/DateInput/DateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ export interface DatePickerProps {
* </pre>
*/
dateAdapter?: DateAdapter;
/** Callback fired on datepicker button blur
* @param {FocusEvent<HTMLButtonElement>} event FocusEvent
*/
onDatePickerButtonBlur?: (event: FocusEvent<HTMLButtonElement>) => void;
}
export interface DateInputProps
extends DatePickerProps,
Expand Down Expand Up @@ -212,6 +216,7 @@ const BaseDateInput = (props: DateInputProps) => {
labelText,
labelMode,
onChange: propOnChange,
onDatePickerButtonBlur,
wrapperProps,
optionalText,
status,
Expand Down Expand Up @@ -413,6 +418,11 @@ const BaseDateInput = (props: DateInputProps) => {
})}
onClick={() => toggleCalendar(!calendarVisible)}
disabled={passProps.disabled}
onBlur={(event) => {
if (!!onDatePickerButtonBlur) {
onDatePickerButtonBlur(event);
}
}}
>
<VisuallyHidden>
{buttonDateLabel || texts.openButtonLabel}
Expand Down
4 changes: 2 additions & 2 deletions src/core/Form/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ interface BaseTextInputProps
labelMode?: LabelMode;
/** Placeholder text for the input. Use only as visual aid, not for instructions. */
visualPlaceholder?: string;
/** Hint text to be shown below the component */
/** Hint text to be shown below the component's label */
hintText?: string;
/**
* `'default'` | `'error'`
*
* Status of the component. Error state creates a red border around the Checkbox.
* Status of the component. Error state creates a red border around the input.
* Always use a descriptive `statusText` with an error status.
* @default default
*/
Expand Down
140 changes: 140 additions & 0 deletions src/core/Form/TimeInput/TimeInput.baseStyles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { css } from 'styled-components';
import { SuomifiTheme } from '../../theme';
import { element, containerIEFocus, font } from '../../theme/reset';
import { math } from 'polished';

export const baseStyles = (theme: SuomifiTheme) => css`
${font(theme)('bodyText')}
width: 290px;

& .fi-time-input_character-counter {
${font(theme)('bodyTextSmall')};
color: ${theme.colors.blackBase};
font-size: 14px;
line-height: 20px;
flex: none;
margin-top: 4px;

&.fi-time-input_character-counter--error {
color: ${theme.colors.alertBase};
${font(theme)('bodySemiBoldSmall')};
font-size: 14px;
line-height: 20px;
}
}

& .fi-time-input_bottom-wrapper {
display: flex;
justify-content: space-between;
}

& .fi-time-input_wrapper {
width: 100%;
display: inline-block;

& .fi-time-input_label--visible {
margin-bottom: ${theme.spacing.xs};
}

& .fi-hint-text {
margin-bottom: ${theme.spacing.xs};
}

& .fi-time-input_statusText--has-content {
margin-top: ${theme.spacing.xxs};
}
}

& .fi-time-input_input-element-container {
width: 60px;
${containerIEFocus(theme)}

&:focus-within {
position: relative;
${theme.focuses.highContrastFocus}

&::after {
${theme.focuses.absoluteFocus}
}
}
}

&.fi-time-input--full-width {
width: 100%;
}

& .fi-time-input_input {
${element(theme)}
${font(theme)('actionElementInnerText')}
width: 100%;
border: 1px solid ${theme.colors.depthLight1};
border-radius: ${theme.radiuses.basic};
line-height: 1;
background-color: ${theme.colors.whiteBase};
height: 40px;
padding: ${theme.spacing.insetL};
border-color: ${theme.colors.depthDark3};

&::placeholder {
color: ${theme.colors.depthDark2};
opacity: 1;
text-align: center;
}
&::-ms-clear {
display: none;
width: 0;
height: 0;
}
&::-ms-reveal {
display: none;
width: 0;
height: 0;
}
}

&.fi-time-input_with-icon {
& .fi-time-input_input-element-container {
position: relative;
}

& .fi-time-input_input {
padding-right: ${math(
`${theme.spacing.insetXl} * 2 + ${theme.spacing.insetM}`,
)};
}

& .fi-icon {
position: absolute;
width: 18px;
height: 18px;
top: ${theme.spacing.insetL};
right: ${theme.spacing.insetL};
}
}

&.fi-time-input--error {
& .fi-time-input_input {
border: 2px solid ${theme.colors.alertBase};
padding-left: 9px;
padding-top: 7px;
padding-bottom: 7px;
}
}
&.fi-time-input--success {
& .fi-time-input_input {
border: 2px solid ${theme.colors.successBase};
padding-left: 9px;
padding-top: 7px;
padding-bottom: 7px;
}
}
&.fi-time-input--disabled {
& .fi-time-input_input {
color: ${theme.colors.depthBase};
background-color: ${theme.colors.depthLight3};
}
& .fi-icon-base-fill {
fill: ${theme.colors.depthBase};
}
}
`;
Loading