-
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.
Add timeline history for maltekstseksjoner
- Loading branch information
1 parent
3fb7855
commit 6652d9e
Showing
23 changed files
with
615 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export const CURRENT_YEAR_IN_CENTURY = Number.parseInt(new Date().getFullYear().toString().slice(2), 10); | ||
export const ISO_FORMAT = 'yyyy-MM-dd'; | ||
export const PRETTY_FORMAT = 'dd.MM.yyyy'; | ||
export const PRETTY_DATETIME_FORMAT = 'dd.MM.yyyy HH:mm:ss'; | ||
export const FORMAT = 'yyyy-MM-dd'; | ||
export const ISO_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss"; |
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
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
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
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
51 changes: 51 additions & 0 deletions
51
frontend/src/components/maltekstseksjoner/maltekstseksjon/timeline/pin-time.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,51 @@ | ||
import { format } from 'date-fns'; | ||
import React from 'react'; | ||
import { styled } from 'styled-components'; | ||
import { ISO_DATETIME_FORMAT } from '@app/components/date-picker/constants'; | ||
import { Time } from '@app/components/time/time'; | ||
|
||
interface Props { | ||
from: Date; | ||
to: Date; | ||
value: Date; | ||
onChange: (value: Date) => void; | ||
} | ||
|
||
export const PinTime = ({ from, to, value, onChange }: Props) => { | ||
const minTime = from.getTime(); | ||
const maxTime = to.getTime(); | ||
const length = maxTime - minTime; | ||
const min = 0; | ||
const max = length; | ||
const step = length / 1_000; | ||
|
||
return ( | ||
<Container> | ||
<Time date={to} /> | ||
<input | ||
type="datetime-local" | ||
value={format(value, ISO_DATETIME_FORMAT)} | ||
onChange={(e) => onChange(new Date(Number.parseInt(e.target.value, 10)))} | ||
/> | ||
<RangeInput | ||
type="range" | ||
min={min} | ||
max={max} | ||
step={step} | ||
onChange={(e) => onChange(new Date(maxTime - Number.parseInt(e.target.value, 10)))} | ||
value={maxTime - value.getTime()} | ||
/> | ||
<Time date={from} /> | ||
</Container> | ||
); | ||
}; | ||
|
||
const Container = styled.div` | ||
display: flex; | ||
flex-direction: row; | ||
gap: 8px; | ||
`; | ||
|
||
const RangeInput = styled.input` | ||
flex-grow: 1; | ||
`; |
Oops, something went wrong.