Skip to content

Commit 1159864

Browse files
Merge pull request #36 from linked-planet/dev
Dev
2 parents 838f88c + ce8960e commit 1159864

File tree

8 files changed

+1182
-231
lines changed

8 files changed

+1182
-231
lines changed

library/src/components/ToastFlag.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export function showFlagExtended({
141141
appearance={appearance}
142142
type={flagType}
143143
style={flagStyle}
144-
className="bottom-0 bg-transparent p-0"
144+
className="bottom-0 bg-transparent p-0 shadow-none"
145145
{...props}
146146
/>,
147147
{

library/src/components/timetable/TimeTable.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ export interface LPTimeTableProps<
158158
*/
159159
hideOutOfRangeMarkers?: boolean
160160

161+
/**
162+
* The locale to use for the dayjs library
163+
* @default "en"
164+
**/
165+
locale?: "en" | "de"
166+
161167
/**
162168
* If defined this is called by each cell to check if it is disabled
163169
*/
@@ -222,6 +228,7 @@ const LPTimeTableImpl = <G extends TimeTableGroup, I extends TimeSlotBooking>({
222228
showTimeSlotHeader,
223229
hideOutOfRangeMarkers = false,
224230
nowOverwrite,
231+
locale = "en",
225232
dateHeaderTextFormat,
226233
weekStartsOnSunday = false,
227234
disableMessages = false,
@@ -478,6 +485,7 @@ const LPTimeTableImpl = <G extends TimeTableGroup, I extends TimeSlotBooking>({
478485
}
479486
dateHeaderTextFormat={dateHeaderTextFormat}
480487
weekStartsOnSunday={weekStartsOnSunday}
488+
locale={locale}
481489
ref={tableHeaderRef}
482490
/>
483491
<tbody ref={tableBodyRef} className="table-fixed">

library/src/components/timetable/TimeTableHeader.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
import dayjs, { type Dayjs } from "dayjs"
22
import weekOfYear from "dayjs/plugin/weekOfYear"
33
import weekYear from "dayjs/plugin/weekYear"
4+
import localeData from "dayjs/plugin/localeData"
45
dayjs.extend(weekOfYear)
56
dayjs.extend(weekYear)
7+
dayjs.extend(localeData)
68
import type React from "react"
79
import { Fragment, forwardRef } from "react"
810

11+
// if more locales then english and germans are needed, we need to enable them first here
12+
import "dayjs/locale/de"
13+
//import "dayjs/locale/es"
14+
//import "dayjs/locale/fr"
15+
//import "dayjs/locale/it"
16+
//import "dayjs/locale/nl"
17+
918
import type { TimeTableViewType } from "./TimeTable"
1019
import type { TimeFrameDay } from "./TimeTableConfigStore"
1120

12-
const headerTimeSlotFormat = "HH:mm"
21+
const headerTimeSlotFormat: { [viewType in TimeTableViewType]: string } = {
22+
hours: "HH:mm",
23+
days: "dd HH:mm",
24+
weeks: "HH:mm",
25+
months: "HH:mm",
26+
years: "HH:mm",
27+
}
1328

1429
export function headerText(
1530
tsStart: Dayjs,
@@ -49,6 +64,7 @@ type TimeTableHeaderProps = {
4964
/** a dayjs format string */
5065
dateHeaderTextFormat?: string
5166
weekStartsOnSunday: boolean
67+
locale?: "en" | "de"
5268
}
5369

5470
export const LPTimeTableHeader = forwardRef(function TimeTableHeader(
@@ -63,9 +79,15 @@ export const LPTimeTableHeader = forwardRef(function TimeTableHeader(
6379
timeFrameDay,
6480
dateHeaderTextFormat,
6581
weekStartsOnSunday,
82+
locale,
6683
}: TimeTableHeaderProps,
6784
tableHeaderRef: React.Ref<HTMLTableSectionElement>,
6885
) {
86+
const currentLocale = dayjs.locale()
87+
if (locale && locale !== currentLocale) {
88+
dayjs.locale(locale)
89+
}
90+
6991
const viewTypeUnit = viewType === "hours" ? "days" : viewType
7092
const daysOrWeeksOrMonths = [
7193
...new Set(
@@ -217,7 +239,9 @@ export const LPTimeTableHeader = forwardRef(function TimeTableHeader(
217239
} ${showTimeSlotHeader ? "pt-1" : ""}`}
218240
>
219241
{showTimeSlotHeader
220-
? slot.format(headerTimeSlotFormat)
242+
? slot.format(
243+
headerTimeSlotFormat[viewType],
244+
)
221245
: undefined}
222246
</th>
223247
)

0 commit comments

Comments
 (0)