Skip to content

Commit

Permalink
fix(core): refine datepicker sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
fynnfeldpausch committed Apr 25, 2024
1 parent c67bcb2 commit 79076a9
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 58 deletions.
4 changes: 2 additions & 2 deletions angular/projects/catalyst/src/lib/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,15 @@ export declare interface CatDate extends Components.CatDate {
}

@ProxyCmp({
inputs: ['hint', 'max', 'min', 'noClear', 'noToday', 'range', 'size', 'value', 'weeks'],
inputs: ['hint', 'max', 'min', 'noClear', 'noToday', 'range', 'value', 'weeks'],
methods: ['select', 'clear', 'resetView']
})
@Component({
selector: 'cat-date-inline',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: ['hint', 'max', 'min', 'noClear', 'noToday', 'range', 'size', 'value', 'weeks']
inputs: ['hint', 'max', 'min', 'noClear', 'noToday', 'range', 'value', 'weeks']
})
export class CatDateInline {
protected el: HTMLElement;
Expand Down
8 changes: 0 additions & 8 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,6 @@ export namespace Components {
* @param date The date to select.
*/
"select": (date: Date | null) => Promise<void>;
/**
* The size of the date picker.
*/
"size": 's' | 'm';
/**
* The value of the control, given in local ISO 8601 date format YYYY-MM-DD.
*/
Expand Down Expand Up @@ -2569,10 +2565,6 @@ declare namespace LocalJSX {
* Allow the selection of a range of dates, i.e. start and end date.
*/
"range"?: boolean;
/**
* The size of the date picker.
*/
"size"?: 's' | 'm';
/**
* The value of the control, given in local ISO 8601 date format YYYY-MM-DD.
*/
Expand Down
2 changes: 2 additions & 0 deletions core/src/components/cat-button/cat-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ $button-sizes: (
:host(.cat-date-item) {
.cat-button {
padding: 0;
min-width: 2rem;
max-height: 3rem;
aspect-ratio: 1;
}
}
Expand Down
71 changes: 32 additions & 39 deletions core/src/components/cat-date-inline/cat-date-inline.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@use 'mixins' as *;

:host {
display: inline-block;
display: block;
}

:host([hidden]) {
Expand All @@ -12,42 +12,33 @@
.picker {
display: flex;
flex-direction: column;
min-width: calc(2rem + 7 * 2.5rem);
max-width: calc(2rem + 7 * 4rem);

&.picker-weeks {
min-width: calc(7 * 2.5rem);
max-width: calc(7 * 4rem);
}

&.picker-small {
min-width: calc(2rem + 7 * 2rem);
max-width: calc(2rem + 7 * 3rem);

&.picker-weeks {
min-width: calc(7 * 2rem);
max-width: calc(7 * 3rem);
}
}
gap: 0.5rem;
}

.picker-head {
display: flex;
gap: 0.5rem;
align-items: center;
container-type: inline-size;

> :not(:last-child) {
// we use margin here instead of gap to be able to properly adjust by container query
margin-right: 0.25rem;
}

h3 {
@include cat-head(4);
@include cat-head(5);
flex: 1;
text-align: center;
margin: 0;
margin-block: 0;
}

.picker-small & {
gap: 0.25rem;

@container (min-width: 20rem) {
h3 {
@include cat-head(5);
@include cat-head(4);
}

> :not(:last-child) {
margin-right: 0.5rem;
}
}
}
Expand All @@ -66,7 +57,6 @@
'd d d d d d d'
'd d d d d d d';
/* stylelint-enable declaration-block-no-redundant-longhand-properties */
margin: 1rem 0 0.5rem;

.picker-weeks & {
/* stylelint-disable declaration-block-no-redundant-longhand-properties */
Expand All @@ -81,10 +71,6 @@
'w d d d d d d d';
/* stylelint-enable declaration-block-no-redundant-longhand-properties */
}

.picker-small & {
margin: 0.5rem 0;
}
}

.picker-grid-head {
Expand Down Expand Up @@ -127,20 +113,31 @@

.picker-foot {
display: flex;
gap: 1rem;
align-items: center;
width: min-content;
min-width: 100%;
justify-content: space-between;
container-type: inline-size;

.picker-small & {
gap: 0.5rem;
> :not(:last-child) {
// we use margin here instead of gap to be able to properly adjust by container query
margin-right: 0.25rem;
}

@container (min-width: 20rem) {
> :not(:last-child) {
margin-right: 0.5rem;
}

.cursor-help {
@include cat-body('s');
}
}
}

.cursor-help {
margin: 0;
@include cat-body('s');
margin-block: 0;
@include cat-body('xs');
color: cat-token('color.ui.font.muted') !important;
text-align: center;
flex: 1;
Expand All @@ -156,10 +153,6 @@
&:only-child {
text-align: center;
}

.picker-small & {
@include cat-body('xs');
}
}

.cursor-aria {
Expand Down
8 changes: 1 addition & 7 deletions core/src/components/cat-date-inline/cat-date-inline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ export class CatDateInline {
*/
@Prop() weeks = false;

/**
* The size of the date picker.
*/
@Prop() size: 's' | 'm' = 'm';

/**
* A minimum value for the date, given in local ISO 8601 date format YYYY-MM-DD.
*/
Expand Down Expand Up @@ -182,7 +177,7 @@ export class CatDateInline {
const [dateStart, dateEnd] = this.getValue();
return (
<Host>
<div class={{ picker: true, 'picker-small': this.size === 's', 'picker-weeks': this.weeks }}>
<div class={{ picker: true, 'picker-weeks': this.weeks }}>
<div class="picker-head">
<cat-button
icon="$cat:datepicker-year-prev"
Expand Down Expand Up @@ -259,7 +254,6 @@ export class CatDateInline {
'date-focusable': this.canFocus(day),
'date-disabled': !this.canClick(day)
}}
size={this.size}
nativeAttributes={!this.canFocus(day) ? { tabindex: '-1' } : {}}
variant={isStartDate || isEndDate ? 'filled' : isToday ? 'outlined' : 'text'}
a11yLabel={this.locale.toLocalStr(day)}
Expand Down
1 change: 0 additions & 1 deletion core/src/components/cat-date-inline/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ An inline date picker component to select a date.
| `noClear` | `no-clear` | Hides the clear button. | `boolean` | `false` |
| `noToday` | `no-today` | Hides the today button. | `boolean` | `false` |
| `range` | `range` | Allow the selection of a range of dates, i.e. start and end date. | `boolean` | `false` |
| `size` | `size` | The size of the date picker. | `"m" \| "s"` | `'m'` |
| `value` | `value` | The value of the control, given in local ISO 8601 date format YYYY-MM-DD. | `string \| undefined` | `undefined` |
| `weeks` | `weeks` | Show week numbers. | `boolean` | `false` |

Expand Down
1 change: 1 addition & 0 deletions core/src/components/cat-date/cat-date.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@

cat-date-inline {
margin: 1rem;
width: 20rem;
}
1 change: 0 additions & 1 deletion vue/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export const CatDateInline = /*@__PURE__*/ defineContainer<JSX.CatDateInline>('c
'hint',
'noToday',
'weeks',
'size',
'min',
'max',
'range',
Expand Down

0 comments on commit 79076a9

Please sign in to comment.