From 2f5d57fa99ca0398cdd80deff77f99c088b045c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuva=20=C3=98deg=C3=A5rd?= Date: Tue, 12 Nov 2024 08:54:43 +0100 Subject: [PATCH] =?UTF-8?q?chore:=20pusher=20for=20at=20peter=20kan=20se?= =?UTF-8?q?=20p=C3=A5,=20ikke=20ferdig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/calendar/Calendar.tsx | 8 + .../src/calendar/Header.tsx | 50 +- .../src/datelogic/simplecalendar.ts | 20 + .../src/datepicker/Datepicker.stories.tsx | 2 +- .../src/datepicker/Datepicker.tsx | 529 +++++++++--------- packages/ffe-datepicker/less/calendar.less | 6 +- packages/ffe-datepicker/less/dateinput.less | 53 +- 7 files changed, 364 insertions(+), 304 deletions(-) diff --git a/packages/ffe-datepicker-react/src/calendar/Calendar.tsx b/packages/ffe-datepicker-react/src/calendar/Calendar.tsx index c6ee7d8a75..567f93a9be 100644 --- a/packages/ffe-datepicker-react/src/calendar/Calendar.tsx +++ b/packages/ffe-datepicker-react/src/calendar/Calendar.tsx @@ -168,6 +168,11 @@ export class Calendar extends Component { this.forceUpdate(); } + changeMonth(value: number) { + this.state.calendar.changeMonth(value); + this.forceUpdate(); + } + renderDate(calendarButtonState: CalendarButtonState, index: number) { const { calendar } = this.state; @@ -278,7 +283,10 @@ export class Calendar extends Component { nextMonthLabel={calendar.nextName} previousMonthHandler={this.previousMonth} previousMonthLabel={calendar.previousName} + changeMonthHandler={this.changeMonth} year={calendar.focusedYear} + startYear={calendar.minDate?.year} + endYear={calendar.maxDate?.year} prevMonthButtonElement={this.prevMonthButtonElementRef} nextMonthButtonElement={this.nextMonthButtonElementRef} /> diff --git a/packages/ffe-datepicker-react/src/calendar/Header.tsx b/packages/ffe-datepicker-react/src/calendar/Header.tsx index 4b525f5ee3..c4b50b115e 100644 --- a/packages/ffe-datepicker-react/src/calendar/Header.tsx +++ b/packages/ffe-datepicker-react/src/calendar/Header.tsx @@ -1,5 +1,7 @@ import React from 'react'; import { Icon } from '@sb1/ffe-icons-react'; +import { Dropdown } from '@sb1/ffe-dropdown-react'; +import { getAllMonths, getAllYears } from '../datelogic/simplecalendar'; interface HeaderProps { datepickerId: string; @@ -8,7 +10,10 @@ interface HeaderProps { nextMonthLabel: string; previousMonthHandler: React.MouseEventHandler; previousMonthLabel: string; + changeMonthHandler: (value: number) => void; year: number; + startYear?: number; + endYear?: number; prevMonthButtonElement: React.RefObject; nextMonthButtonElement: React.RefObject; } @@ -20,7 +25,10 @@ export const Header: React.FC = ({ nextMonthLabel, previousMonthHandler, previousMonthLabel, + changeMonthHandler, year, + startYear = new Date().getFullYear() - 100, + endYear = new Date().getFullYear(), prevMonthButtonElement, nextMonthButtonElement, }) => { @@ -49,9 +57,45 @@ export const Header: React.FC = ({ className="ffe-calendar__title" id={`${datepickerId}-title`} > -
- {month} - {year} +
+ + { + console.log('e', e.target.value); + changeMonthHandler( + parseInt(e.target.value), + ); + }} + > + {getAllMonths('nb').map( + (monthOption, index) => { + return ( + + ); + }, + )} + + + + + {getAllYears(startYear, endYear).map( + (yearOption, index) => { + return ( + + ); + }, + )} + +
+ {displayDatePicker && ( + { + if (evt.key === 'Escape') { + closeCalendarSetInputFocus(); + } + }} + locale={locale} + maxDate={maxDate} + minDate={minDate} + onDatePicked={datePickedHandler} + selectedDate={calendarActiveDate} + focusOnMount={true} + /> + )} - ); - } -} + + ); +}; diff --git a/packages/ffe-datepicker/less/calendar.less b/packages/ffe-datepicker/less/calendar.less index 3c2939fe3c..392fd5a673 100644 --- a/packages/ffe-datepicker/less/calendar.less +++ b/packages/ffe-datepicker/less/calendar.less @@ -28,7 +28,7 @@ &__header-inner-wrapper { display: flex; - justify-content: center; + justify-content: space-between; align-items: center; } @@ -61,6 +61,10 @@ } } + &__month-label { + display: flex; + } + &__icon-prev.ffe-icons, &__icon-next.ffe-icons { color: var(--ffe-v-datepicker-icon-color); diff --git a/packages/ffe-datepicker/less/dateinput.less b/packages/ffe-datepicker/less/dateinput.less index ff898d198e..143038e687 100644 --- a/packages/ffe-datepicker/less/dateinput.less +++ b/packages/ffe-datepicker/less/dateinput.less @@ -1,37 +1,49 @@ .ffe-dateinput { position: relative; display: inline-block; + grid-column: 1 e('/') 3; + grid-row: 1 e('/') -1; + min-width: 210px; &--full-width { display: block; } + // + //@media (hover: hover) and (pointer: fine) { + // &:hover { + // color: var(--ffe-g-primary-color); + // } + //} - @media (hover: hover) and (pointer: fine) { - &:hover { - color: var(--ffe-g-primary-color); - } + &[aria-invalid='true'] { + border-color: var(--ffe-g-error-color); + border-style: solid; + } + + //@media (hover: hover) and (pointer: fine) { + // /* stylelint-disable selector-max-specificity */ + // &:focus + .ffe-datepicker__button:hover { + // border-color: red !important; + // box-shadow: 0 0 0 2px var(--ffe-v-datepicker-border-hover-color); + // } + // /* stylelint-enable selector-max-specificity */ + //} + + &.ffe-input-field { + display: flex; + align-items: center; } &__field { - min-width: 160px; - grid-column: 1 e('/') 3; - grid-row: 1 e('/') -1; - &::-ms-clear { - display: none; - } + padding-block: var(--ffe-spacing-2xs); - &[aria-invalid='true'] { - border-color: var(--ffe-g-error-color); - border-style: solid; + &:focus { + background-color: var(--ffe-farge-frost-30); + outline: none; } - @media (hover: hover) and (pointer: fine) { - /* stylelint-disable selector-max-specificity */ - &:focus + .ffe-datepicker__button:hover { - border-color: transparent; - box-shadow: 0 0 0 2px var(--ffe-v-datepicker-border-hover-color); - } - /* stylelint-enable selector-max-specificity */ + &::-ms-clear { + display: none; } } } @@ -60,6 +72,7 @@ transition: all var(--ffe-transition-duration) var(--ffe-ease); width: 56px; cursor: pointer; + z-index: 1; &:focus, &:active {