Skip to content

Commit

Permalink
Improve date slider layout & dependencies for futher dev
Browse files Browse the repository at this point in the history
  • Loading branch information
nfour committed Nov 9, 2023
1 parent 4744998 commit f471ef9
Show file tree
Hide file tree
Showing 7 changed files with 2,081 additions and 593 deletions.
48 changes: 27 additions & 21 deletions libs/date-slider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,44 @@
"version": "10.0.0",
"main": "./x/index",
"scripts": {
"build": "tsc",
"dev": "tsc --watch"
"build": "tsc -p tsconfig.build.json",
"dev": "pnpm build -w",
"dev:stories": "ladle dev"
},
"dependencies": {
"react-use": "^17.4.0",
"luxon": "^3.0.3"
"luxon": "^3.0.3",
"react-use": "^17.4.0"
},
"peerDependencies": {
"@dhi/arsenal.ui": "workspace:*",
"@emotion/react": "11",
"@emotion/styled": "11",
"@mui/icons-material": "5",
"@mui/material": "5",
"mobx": "6",
"mobx-react-lite": "3",
"react": ">= 17",
"react-dom": ">= 17"
"@mui/icons-material": ">= 5",
"@mui/material": ">= 5",
"mobx": ">= 6",
"mobx-react-lite": ">= 4",
"react": ">= 18",
"react-dom": ">= 18"
},
"devDependencies": {
"@dhi/arsenal.ui": "workspace:*",
"@emotion/react": "^11.3.0",
"@emotion/styled": "^11.3.0",
"@mui/icons-material": "^5.4.2",
"@mui/material": "^5.4.3",
"@types/node": "^18.0.6",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@fontsource/roboto": "^5.0.8",
"@ladle/react": "^3.3.1",
"@mui/icons-material": "^5.14.16",
"@mui/material": "^5.14.17",
"@types/luxon": "^3.0.1",
"@types/react": "^18.2.28",
"@types/node": "^18.0.6",
"@types/react": "^18.2.37",
"@vitejs/plugin-react": "^4.1.1",
"mobx": "^6.10.2",
"mobx-react-lite": "^3.2.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"typescript": "^4.8.3"
"mobx-react-lite": "^4.0.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "^5.2.2",
"vite": "^4.5.0",
"vite-plugin-build": "^0.10.0",
"vite-plugin-dts": "^3.6.3"
},
"repository": {
"type": "git",
Expand Down
22 changes: 14 additions & 8 deletions libs/date-slider/src/DateSlider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IconButton } from '@mui/material';
import { Grid, IconButton } from '@mui/material';
import {
ChevronLeft as ArrowBack,
ChevronRight as ArrowForward,
Expand All @@ -8,8 +8,8 @@ import { makeAutoObservable } from 'mobx';
import { observer } from 'mobx-react-lite';
import * as React from 'react';
import { useMeasure } from 'react-use';
import { $Row, $Col } from '@dhi/arsenal.ui/x/components';
import { css, styled } from '@dhi/arsenal.ui/x';
import styled from '@emotion/styled';
import { css } from '@emotion/react';

export type SliderPoint = SliderRangePoint | SliderDatePoint;
export interface SliderDatePoint {
Expand Down Expand Up @@ -210,12 +210,17 @@ export const DateSlider = observer<{
);

return (
<$Row
<Grid
direction={'row'}
container
flexGrow={1}
alignItems={'center'}
flexWrap={'nowrap'}
gap={'1.5em'}
{...{ className }}
css={css`
padding: 0.75em 1.5em;
width: 100%;
flex-grow: 1;
`}
>
<$PrevNextIconButton
Expand All @@ -230,7 +235,7 @@ export const DateSlider = observer<{
>
<ArrowBack color="secondary" />
</$PrevNextIconButton>
<$Col ref={ref as any} grow>
<Grid container ref={ref as any} flexGrow={1}>
<div
css={css`
position: relative;
Expand Down Expand Up @@ -398,7 +403,7 @@ export const DateSlider = observer<{
</div>
))}
</div>
</$Col>
</Grid>
<$PrevNextIconButton
disableTouchRipple
disableFocusRipple
Expand All @@ -411,14 +416,15 @@ export const DateSlider = observer<{
>
<ArrowForward />
</$PrevNextIconButton>
</$Row>
</Grid>
);
},
);

const $PrevNextIconButton = styled(IconButton)`
box-shadow: 0 1px 4px rgba(0, 0, 0, 0);
padding: 0;
margin-top: -0.5ex;
&:hover {
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
Expand Down
86 changes: 86 additions & 0 deletions libs/date-slider/src/__stories__/dateSlider.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import '@fontsource/roboto';
import { css, PropsOf } from '@emotion/react';
import { useState } from 'react';
import { DateTime } from 'luxon';
import { DateSlider } from '..';
import { CssBaseline, Grid } from '@mui/material';

export default {
title: 'DateSlider',
};

export const Scenario1 = () => {
const [activeId, setActiveId] = useState(undefined);
// One year diff
const start = DateTime.fromFormat('2020-01-01', 'yyyy-MM-dd');
const end = DateTime.fromFormat('2021-01-01', 'yyyy-MM-dd');
const sliderProps: PropsOf<typeof DateSlider> = {
onChange: (p) => {
setActiveId(p?.id);
},
activeId,
start: start.toJSDate(),
end: end.toJSDate(),
points: [
{
id: 0,
start: start.plus({ months: 2 }).toJSDate(), // March
end: start.plus({ months: 4 }).toJSDate(),
},
{
id: 1,
start: start.plus({ months: 4 }).toJSDate(), // June
end: start.plus({ months: 6 }).toJSDate(),
},
{
id: 2,
start: start.plus({ months: 7 }).toJSDate(), // August
end: start.plus({ months: 10 }).toJSDate(),
},
],
};

/**
* show date range for 3 ranges
* monthly periods
* shows proportional label & points
*/
return (
<>
<CssBaseline />
<Grid
container
gap={'2em'}
css={css`
padding: 1em;
`}
>
<DateSlider
{...sliderProps}
css={css`
max-width: 500px;
`}
/>
<DateSlider
{...sliderProps}
css={css`
max-width: 900px;
`}
/>
<DateSlider
{...sliderProps}
css={css`
max-width: 1200px;
`}
/>
<DateSlider
{...sliderProps}
css={css`
max-width: 1600px;
`}
/>
<DateSlider {...sliderProps} />
</Grid>
</>
);
};
10 changes: 10 additions & 0 deletions libs/date-slider/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "./x"
},
"include": [
"src"
]
}
6 changes: 2 additions & 4 deletions libs/date-slider/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"target": "ES2020",
"target": "ESNext",
"skipLibCheck": true,
"rootDir": "src",
"outDir": "./x"
},
"include": [ "src"],
"include": [ "src", "*.ts"],
"references": [
{ "path": "../models" },
{ "path": "../ui" },
]
}
6 changes: 6 additions & 0 deletions libs/date-slider/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'vite';
import reactPlugin from '@vitejs/plugin-react';

export default defineConfig({
plugins: [reactPlugin({ jsxImportSource: '@emotion/react' })],
});
Loading

0 comments on commit f471ef9

Please sign in to comment.