This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
forked from danskernesdigitalebibliotek/dpl-design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35495a0
commit 6b4c57b
Showing
6 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/stories/Library/Forms/date-picker/DatePicker.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ComponentStory, ComponentMeta } from "@storybook/react"; | ||
import { withDesign } from "storybook-addon-designs"; | ||
import DatePicker from "./DatePicker"; | ||
|
||
export default { | ||
title: "Library / Forms / DatePicker", | ||
component: DatePicker, | ||
decorators: [withDesign], | ||
argTypes: {}, | ||
parameters: { | ||
design: { | ||
type: "figma", | ||
url: "https://www.figma.com/file/Zx9GrkFA3l4ISvyZD2q0Qi/Designsystem?type=design&node-id=7605%3A54868&mode=design&t=MoXpQuI4TAXRxRDe-1", | ||
}, | ||
layout: "fullscreen", | ||
}, | ||
} as ComponentMeta<typeof DatePicker>; | ||
|
||
const Template: ComponentStory<typeof DatePicker> = () => <DatePicker />; | ||
|
||
export const Default = Template.bind({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Import default styling | ||
import "flatpickr/dist/flatpickr.css"; | ||
|
||
import flatpickr from "flatpickr"; | ||
import { english } from "flatpickr/dist/l10n/default"; | ||
import { Danish } from "flatpickr/dist/l10n/da"; | ||
import { Instance } from "flatpickr/dist/types/instance"; | ||
import { MutableRefObject, useCallback, useRef } from "react"; | ||
import { BaseOptions } from "flatpickr/dist/types/options"; | ||
|
||
export type DatePickerProps = { | ||
locale?: "en" | "da"; | ||
}; | ||
|
||
const DatePicker = (props: DatePickerProps) => { | ||
const { locale = "en" } = props; | ||
const picker = useRef() as MutableRefObject<Instance>; | ||
|
||
const pickerRef = useCallback( | ||
(node: Node | null) => { | ||
const options: Partial<BaseOptions> = { | ||
wrap: true, | ||
static: true, | ||
locale: locale === "en" ? english : Danish, | ||
}; | ||
|
||
if (node !== null) { | ||
picker.current = flatpickr(node, options); | ||
} | ||
}, | ||
[locale] | ||
); | ||
|
||
return ( | ||
<div className="datepicker"> | ||
<div className="datepicker__wrapper" ref={pickerRef}> | ||
<input | ||
type="text" | ||
placeholder="Date" | ||
className="datepicker__input" | ||
data-input | ||
/> | ||
<button | ||
name="Toggle datepicker" | ||
className="datepicker__opener" | ||
data-toggle | ||
> | ||
<img | ||
className="datepicker__icon" | ||
src="icons/collection/ExpandMore.svg" | ||
alt="Expand more icon" | ||
/> | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DatePicker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.datepicker { | ||
&__wrapper { | ||
position: relative; | ||
width: 100%; | ||
height: 48px; | ||
background-color: transparent; | ||
display: flex; | ||
align-items: center; | ||
flex-direction: row; | ||
border: 1px solid $c-global-tertiary-1; | ||
} | ||
|
||
& .flatpickr-calendar * { | ||
font-family: "Noto Sans JP", sans-serif; | ||
} | ||
|
||
&__input { | ||
@extend %text-button-placeholder; | ||
width: 100%; | ||
height: 100%; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
padding: 0 $s-md; | ||
border: none; | ||
cursor: pointer; | ||
} | ||
|
||
&__opener { | ||
width: 44px; | ||
min-width: 44px; | ||
height: 48px; | ||
border-left: 1px solid $c-global-tertiary-1; | ||
display: flex; | ||
align-items: center; | ||
cursor: pointer; | ||
} | ||
|
||
&__icon { | ||
margin: auto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters