Skip to content

Commit

Permalink
feat(date-field): add isCondensed prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Creasman authored and Jonathan Creasman committed Apr 22, 2024
1 parent d30700f commit 4581041
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/modern-berries-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@commercetools-uikit/date-input': minor
'@commercetools-uikit/calendar-utils': minor
---

Add isCondensed prop that when set to true, condenses the input height, icon size and font size.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ const getInputContainerStyles = (props: TCalendarBody, state: TState) => {
color: ${getInputFontColor(props)};
cursor: ${props.isDisabled ? 'not-allowed' : 'default'};
width: 100%;
height: ${designTokens.heightForInput};
height: ${props.inputProps?.isCondensed
? `${designTokens.heightForInputAsSmall}`
: `${designTokens.heightForInput}`};
align-items: center;
display: flex;
font-size: ${designTokens.fontSize30};
Expand Down Expand Up @@ -203,6 +205,9 @@ const getDateTimeInputStyles = (props: TCalendarBody) => {
&:focus:not(:read-only) {
box-shadow: none;
}
font-size: ${props.inputProps?.isCondensed
? `${designTokens.fontSize20}`
: `${designTokens.fontSize30}`};
`,
];
return baseStyles;
Expand Down
10 changes: 8 additions & 2 deletions packages/calendar-utils/src/calendar-body/calendar-body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from './calendar-body.styles';

export type TClearSection = {
isCondensed?: boolean;
isDisabled?: boolean;
hasError?: boolean;
hasWarning?: boolean;
Expand All @@ -35,7 +36,7 @@ export const ClearSection = (props: TClearSection) => {
onClick={props.onClear}
aria-label="clear"
>
<CloseIcon size="medium" />
<CloseIcon size={props.isCondensed ? 'small' : 'medium'} />
</AccessibleButton>
);
};
Expand All @@ -50,6 +51,7 @@ export type TInputProps = {
* HTML ID of an element containing an error message related to the input.
*/
'aria-errormessage'?: string;
isCondensed?: boolean;
onBlur?: FocusEventHandler;
onFocus?: FocusEventHandler;
onKeyDown?: (
Expand Down Expand Up @@ -141,6 +143,7 @@ export const CalendarBody = (props: TCalendarBody) => {
/>
{!disabledOrReadOnly && props.hasSelection && props.isClearable && (
<ClearSection
isCondensed={props.inputProps?.isCondensed}
hasError={props.hasError}
hasWarning={props.hasWarning}
isFocused={isFocused}
Expand All @@ -162,7 +165,10 @@ export const CalendarBody = (props: TCalendarBody) => {
{props.icon === 'clock' ? (
<ClockIcon color="neutral60" />
) : (
<CalendarIcon color="neutral60" />
<CalendarIcon
color="neutral60"
size={props.inputProps?.isCondensed ? 'medium' : 'big'}
/>
)}
</button>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/components/inputs/date-input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default Example;
| `aria-errormessage` | `string` | | | HTML ID of an element containing an error message related to the input. |
| `name` | `string` | | | Used as the HTML `name` attribute. |
| `placeholder` | `string` | | | Placeholder value to show in the input field |
| `isCondensed` | `boolean` | | | Use this property to reduce the paddings of the component for a ui compact variant |
| `isDisabled` | `boolean` | | | Disables the date picker |
| `isReadOnly` | `boolean` | | | Disables the date picker menu and makes input field read-only |
| `hasError` | `boolean` | | | Indicates the input field has an error |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ storiesOf('Components|Inputs', module)
id={text('id', '')}
name={text('name', '')}
placeholder={placeholder === '' ? undefined : placeholder}
isCondensed={boolean('isCondensed', false)}
isDisabled={boolean('isDisabled', false)}
isReadOnly={boolean('isReadOnly', false)}
hasError={boolean('hasError', false)}
Expand Down
5 changes: 5 additions & 0 deletions packages/components/inputs/date-input/src/date-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ export type TDateInput = {
* Placeholder value to show in the input field
*/
placeholder?: string;
/**
* Use this property to reduce the paddings of the component for a ui compact variant
*/
isCondensed?: boolean;
/**
* Disables the date picker
*/
Expand Down Expand Up @@ -267,6 +271,7 @@ const DateInput = (props: TDateInput) => {
// Unset the aria-labelledby as it interfers with the link
// between the <label for> and the <input id>.
'aria-labelledby': undefined,
isCondensed: props.isCondensed,
name: props.name,
placeholder:
typeof props.placeholder === 'string'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,14 @@ export const component = () => (
hasError
/>
</Spec>
<Spec label="with isCondensed">
<DateInput
value=""
onChange={() => {}}
isCondensed={true}
horizontalConstraint={7}
placeholder="Select something"
/>
</Spec>
</Suite>
);

0 comments on commit 4581041

Please sign in to comment.