willba-component-library 0.0.33 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/lib/components/FilterBar/FilterBar.d.ts +7 -1
  2. package/lib/components/FilterBar/FilterBar.stories.d.ts +2 -2
  3. package/lib/components/FilterBar/components/calendar/Calendar.d.ts +4 -3
  4. package/lib/components/FilterBar/hooks/useFilterBar.d.ts +8 -5
  5. package/lib/i18n.d.ts +2 -0
  6. package/lib/index.d.ts +4 -1
  7. package/lib/index.esm.js +2648 -56
  8. package/lib/index.esm.js.map +1 -1
  9. package/lib/index.js +2647 -55
  10. package/lib/index.js.map +1 -1
  11. package/lib/index.umd.js +2647 -55
  12. package/lib/index.umd.js.map +1 -1
  13. package/lib/themes/useTheme.d.ts +5 -0
  14. package/package.json +5 -2
  15. package/rollup.config.mjs +24 -22
  16. package/src/components/FilterBar/FilterBar.css +2 -8
  17. package/src/components/FilterBar/FilterBar.stories.tsx +8 -9
  18. package/src/components/FilterBar/FilterBar.tsx +28 -9
  19. package/src/components/FilterBar/components/calendar/Calendar.css +4 -0
  20. package/src/components/FilterBar/components/calendar/Calendar.tsx +25 -33
  21. package/src/components/FilterBar/components/categories/Categories.tsx +5 -1
  22. package/src/components/FilterBar/components/guests/Guests.tsx +8 -5
  23. package/src/components/FilterBar/hooks/useFilterBar.tsx +10 -5
  24. package/src/i18n.ts +22 -0
  25. package/src/index.ts +3 -3
  26. package/src/locales/en/filterBar.json +17 -0
  27. package/src/locales/fi/filterBar.json +17 -0
  28. package/src/themes/Default.css +13 -0
  29. package/src/themes/Kisakallio.css +3 -0
  30. package/src/themes/Pajulahti.css +3 -0
  31. package/src/themes/cssModules.d.ts +5 -0
  32. package/src/themes/useTheme.tsx +32 -0
  33. package/tsconfig.json +7 -1
  34. package/lib/components/FilterBar/components/Callendar.d.ts +0 -2
  35. package/lib/components/FilterBar/components/Divider.d.ts +0 -2
  36. package/lib/components/FilterBar/components/SelectButton.d.ts +0 -2
  37. package/lib/components/FilterBar/components/SubmitButton.d.ts +0 -2
@@ -0,0 +1,5 @@
1
+ type ThemeProps = {
2
+ vendor?: string;
3
+ };
4
+ export default function useTheme({ vendor }: ThemeProps): any;
5
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "willba-component-library",
3
- "version": "0.0.33",
3
+ "version": "0.0.36",
4
4
  "description": "A stroybook 6 with TypeScript demo",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.esm.js",
@@ -16,7 +16,9 @@
16
16
  "dependencies": {
17
17
  "classnames": "^2.3.2",
18
18
  "date-fns": "^2.30.0",
19
- "react-day-picker": "^8.8.0"
19
+ "i18next": "^23.4.4",
20
+ "react-day-picker": "^8.8.0",
21
+ "react-i18next": "^13.1.1"
20
22
  },
21
23
  "peerDependencies": {
22
24
  "react": "^18.2.0",
@@ -24,6 +26,7 @@
24
26
  },
25
27
  "devDependencies": {
26
28
  "@rollup/plugin-commonjs": "^25.0.3",
29
+ "@rollup/plugin-json": "^6.0.0",
27
30
  "@rollup/plugin-node-resolve": "^15.1.0",
28
31
  "@rollup/plugin-typescript": "^11.1.2",
29
32
  "@storybook/addon-essentials": "^7.2.1",
package/rollup.config.mjs CHANGED
@@ -1,41 +1,42 @@
1
- import peerDepsExternal from "rollup-plugin-peer-deps-external";
2
- import resolve from "@rollup/plugin-node-resolve";
3
- import commonjs from "@rollup/plugin-commonjs";
4
- import typescript from "@rollup/plugin-typescript";
5
- import postcss from "rollup-plugin-postcss";
6
- import dts from "rollup-plugin-dts";
1
+ import peerDepsExternal from 'rollup-plugin-peer-deps-external'
2
+ import resolve from '@rollup/plugin-node-resolve'
3
+ import commonjs from '@rollup/plugin-commonjs'
4
+ import typescript from '@rollup/plugin-typescript'
5
+ import postcss from 'rollup-plugin-postcss'
6
+ import dts from 'rollup-plugin-dts'
7
+ import json from '@rollup/plugin-json'
7
8
 
8
9
  // This is required to read package.json file when
9
10
  // using Native ES modules in Node.js
10
11
  // https://rollupjs.org/command-line-interface/#importing-package-json
11
- import { createRequire } from "node:module";
12
- const requireFile = createRequire(import.meta.url);
13
- const packageJson = requireFile("./package.json");
12
+ import { createRequire } from 'node:module'
13
+ const requireFile = createRequire(import.meta.url)
14
+ const packageJson = requireFile('./package.json')
14
15
 
15
16
  const globals = {
16
- react: "React",
17
- "react-dom": "ReactDOM",
18
- "react-query": "ReactQuery",
19
- };
17
+ react: 'React',
18
+ 'react-dom': 'ReactDOM',
19
+ 'react-query': 'ReactQuery',
20
+ }
20
21
 
21
22
  export default [
22
23
  {
23
- input: "src/index.ts",
24
+ input: 'src/index.ts',
24
25
  output: [
25
26
  {
26
27
  file: packageJson.main,
27
- format: "cjs",
28
+ format: 'cjs',
28
29
  sourcemap: true,
29
30
  },
30
31
  {
31
32
  file: packageJson.module,
32
- format: "esm",
33
+ format: 'esm',
33
34
  sourcemap: true,
34
35
  },
35
36
  {
36
- name: "WillbaComponentLibrary",
37
+ name: 'WillbaComponentLibrary',
37
38
  file: `lib/index.umd.js`,
38
- format: "umd",
39
+ format: 'umd',
39
40
  sourcemap: true,
40
41
  globals,
41
42
  },
@@ -46,14 +47,15 @@ export default [
46
47
  commonjs(),
47
48
  typescript(),
48
49
  postcss({
49
- extensions: [".css"],
50
+ extensions: ['.css'],
50
51
  }),
52
+ json(),
51
53
  ],
52
54
  },
53
55
  {
54
- input: "lib/index.d.ts",
55
- output: [{ file: "lib/index.d.ts", format: "es" }],
56
+ input: 'lib/index.d.ts',
57
+ output: [{ file: 'lib/index.d.ts', format: 'es' }],
56
58
  plugins: [dts()],
57
59
  external: [/\.css$/],
58
60
  },
59
- ];
61
+ ]
@@ -27,11 +27,5 @@
27
27
  z-index: 111;
28
28
  border-radius: 40px;
29
29
  width: -webkit-fill-available;
30
- box-shadow: 0px 6px 11px 0px #a7a4a480;
31
- }
32
-
33
-
34
-
35
-
36
-
37
-
30
+ box-shadow: var(--box-shadow);
31
+ }
@@ -1,20 +1,19 @@
1
- import React from "react";
2
- import type { Meta, StoryObj } from "@storybook/react";
3
- import FilterBar from "./FilterBar";
1
+ import type { Meta, StoryObj } from '@storybook/react'
2
+ import FilterBar from './FilterBar'
4
3
 
5
4
  // Default metadata of the story https://storybook.js.org/docs/react/api/csf#default-export
6
5
  const meta: Meta<typeof FilterBar> = {
7
- title: "Components/FilterBar",
6
+ title: 'Components/FilterBar',
8
7
  component: FilterBar,
9
- };
8
+ }
10
9
 
11
- export default meta;
10
+ export default meta
12
11
 
13
12
  // The story type for the component https://storybook.js.org/docs/react/api/csf#named-story-exports
14
- type Story = StoryObj<typeof FilterBar>;
13
+ type Story = StoryObj<typeof FilterBar>
15
14
 
16
15
  export const Primary: Story = {
17
16
  args: {
18
- label: "Primary 😃",
17
+ vendor: '',
19
18
  },
20
- };
19
+ }
@@ -1,4 +1,5 @@
1
- import React, { useState } from 'react'
1
+ import React from 'react'
2
+ import { useTranslation } from 'react-i18next'
2
3
 
3
4
  import Divider from './components/divider/Divider'
4
5
  import SelectButton from './components/select-button/SelectButton'
@@ -8,16 +9,27 @@ import Guests from './components/guests/Guests'
8
9
  import Categories from './components/categories/Categories'
9
10
 
10
11
  import useFilterBar from './hooks/useFilterBar'
12
+ import useTheme from '../../themes/useTheme'
11
13
 
12
14
  import './FilterBar.css'
15
+ import '../../themes/Default.css'
16
+ import '../../i18n'
17
+
18
+ type FilterBarProps = {
19
+ vendor?: string
20
+ }
21
+
22
+ export default function FilterBar({ vendor }: FilterBarProps) {
23
+ // useTheme({ vendor })
24
+ const { t } = useTranslation('filterBar')
13
25
 
14
- export default function FilterBar() {
15
26
  const {
16
27
  selectedFilter,
17
28
  guestsAdults,
18
29
  guestsKids,
19
30
  categories,
20
- setSelectedFilter,
31
+ calendarRange,
32
+ setCalendarRange,
21
33
  setGuestsAdults,
22
34
  setGuestsKids,
23
35
  setCategories,
@@ -29,19 +41,22 @@ export default function FilterBar() {
29
41
  <div className="filter-bar">
30
42
  <div className="filter-bar-header">
31
43
  <SelectButton
32
- label="Start date"
44
+ label={t('calendar.startDate')}
33
45
  onClick={() => handleSelectedFilter(1)}
34
46
  />
35
47
  <Divider />
36
48
  <SelectButton
37
- label="End date"
49
+ label={t('calendar.endDate')}
38
50
  onClick={() => handleSelectedFilter(2)}
39
51
  />
40
52
  <Divider />
41
- <SelectButton label="Guests" onClick={() => handleSelectedFilter(3)} />
53
+ <SelectButton
54
+ label={t('guests.label')}
55
+ onClick={() => handleSelectedFilter(3)}
56
+ />
42
57
  <Divider />
43
58
  <SelectButton
44
- label="Categories"
59
+ label={t('categories.label')}
45
60
  onClick={() => handleSelectedFilter(4)}
46
61
  />
47
62
  <SubmitButton onClick={handleSubmit} />
@@ -49,8 +64,12 @@ export default function FilterBar() {
49
64
 
50
65
  {selectedFilter && (
51
66
  <div className="filter-bar-container">
52
- {selectedFilter === 1 && <Calendar />}
53
- {selectedFilter === 2 && <Calendar />}
67
+ {(selectedFilter === 1 || selectedFilter === 2) && (
68
+ <Calendar
69
+ calendarRange={calendarRange}
70
+ setCalendarRange={setCalendarRange}
71
+ />
72
+ )}
54
73
  {selectedFilter === 3 && (
55
74
  <Guests
56
75
  guestsAdults={guestsAdults}
@@ -0,0 +1,4 @@
1
+ .filter-bar-calendar {
2
+ display: flex;
3
+ justify-content: center;
4
+ }
@@ -1,41 +1,33 @@
1
- import React, { useState } from "react";
1
+ import React, { useEffect, useState } from 'react'
2
2
 
3
- import { addDays, format } from "date-fns";
4
- import { DateRange, DayPicker } from "react-day-picker";
3
+ import { addDays } from 'date-fns'
4
+ import { DateRange, DayPicker } from 'react-day-picker'
5
5
 
6
- import "react-day-picker/dist/style.css";
6
+ import 'react-day-picker/dist/style.css'
7
+ import './Calendar.css'
7
8
 
8
- const pastMonth = new Date(2020, 10, 15);
9
+ const currentMonth = new Date()
9
10
 
10
- export default function Calendar() {
11
- const defaultSelected: DateRange = {
12
- from: pastMonth,
13
- to: addDays(pastMonth, 4),
14
- };
15
- const [range, setRange] = useState<DateRange | undefined>(defaultSelected);
16
-
17
- let footer = <p>Please pick the first day.</p>;
18
- if (range?.from) {
19
- if (!range.to) {
20
- footer = <p>{format(range.from, "PPP")}</p>;
21
- } else if (range.to) {
22
- footer = (
23
- <p>
24
- {format(range.from, "PPP")}–{format(range.to, "PPP")}
25
- </p>
26
- );
27
- }
11
+ export default function Calendar({ calendarRange, setCalendarRange }: any) {
12
+ const defaultCalendarSelected: DateRange = {
13
+ from: currentMonth,
14
+ to: addDays(currentMonth, 0),
28
15
  }
29
16
 
17
+ useEffect(() => {
18
+ if (!calendarRange) setCalendarRange(defaultCalendarSelected)
19
+ }, [])
20
+
30
21
  return (
31
- <DayPicker
32
- id="test"
33
- mode="range"
34
- numberOfMonths={2}
35
- defaultMonth={pastMonth}
36
- selected={range}
37
- footer={footer}
38
- onSelect={setRange}
39
- />
40
- );
22
+ <div className="filter-bar-calendar">
23
+ <DayPicker
24
+ id="test"
25
+ mode="range"
26
+ numberOfMonths={2}
27
+ defaultMonth={currentMonth}
28
+ selected={calendarRange}
29
+ onSelect={setCalendarRange}
30
+ />
31
+ </div>
32
+ )
41
33
  }
@@ -1,7 +1,11 @@
1
1
  import React, { useState } from 'react'
2
+ import { useTranslation } from 'react-i18next'
3
+
2
4
  import './Categories.css'
3
5
 
4
6
  export default function Categories({ categories, setCategories }: any) {
7
+ const { t } = useTranslation('filterBar')
8
+
5
9
  const categoriesPlaceholder = [
6
10
  'Weekend',
7
11
  'Week',
@@ -18,7 +22,7 @@ export default function Categories({ categories, setCategories }: any) {
18
22
 
19
23
  return (
20
24
  <div className="filter-bar-categories">
21
- <h3>CATEGORY</h3>
25
+ <h3>{t('categories.label')}</h3>
22
26
  <div className="categories-filter-inner">
23
27
  {categoriesPlaceholder.map((itm, idx) => (
24
28
  <div key={idx}>
@@ -1,4 +1,5 @@
1
1
  import React from 'react'
2
+ import { useTranslation } from 'react-i18next'
2
3
 
3
4
  import './Guests.css'
4
5
 
@@ -10,14 +11,16 @@ export default function Guests({
10
11
  decrementKids,
11
12
  incrementKids,
12
13
  }: any) {
14
+ const { t } = useTranslation('filterBar')
15
+
13
16
  return (
14
- <div className="search-widget-guests">
15
- <h3>Guests</h3>
16
- <p>Who's coming?</p>
17
+ <div className="filter-bar-guests">
18
+ <h3>{t('guests.title')}</h3>
19
+ <p>{t('guests.subtitle')}</p>
17
20
 
18
21
  <div className="guests-filter-container">
19
22
  <div className="guests-filter-inner">
20
- <span>Adults</span>
23
+ <span>{t('guests.adultsLabel')}</span>
21
24
  <div>
22
25
  <button onClick={decrementAdults} disabled={guestsAdults < 1}>
23
26
  -
@@ -27,7 +30,7 @@ export default function Guests({
27
30
  </div>
28
31
  </div>
29
32
  <div className="guests-filter-inner">
30
- <span>Kids</span>
33
+ <span>{t('guests.kidsLabel')}</span>
31
34
  <div>
32
35
  <button onClick={decrementKids} disabled={guestsKids < 1}>
33
36
  -
@@ -1,9 +1,10 @@
1
- import React, { useState } from 'react'
1
+ import { useState } from 'react'
2
+ import { DateRange } from 'react-day-picker'
3
+ import { addDays, format } from 'date-fns'
2
4
 
3
5
  export default function useFilterBar() {
4
6
  const [selectedFilter, setSelectedFilter] = useState<number | boolean>(false)
5
- // const [startDate, setStartDate] = useState(0);
6
- // const [endDate, setEndDate] = useState(0);
7
+ const [calendarRange, setCalendarRange] = useState<DateRange>()
7
8
  const [guestsAdults, setGuestsAdults] = useState(1)
8
9
  const [guestsKids, setGuestsKids] = useState(0)
9
10
  const [categories, setCategories] = useState(0)
@@ -16,8 +17,10 @@ export default function useFilterBar() {
16
17
  const queryParams = new URLSearchParams()
17
18
 
18
19
  const params = {
19
- // startDate,
20
- // endDate,
20
+ startDate: calendarRange?.from
21
+ ? format(calendarRange.from, 'yyyy-MM-dd')
22
+ : '',
23
+ endDate: calendarRange?.to ? format(calendarRange.to, 'yyyy-MM-dd') : '',
21
24
  guestsAdults,
22
25
  guestsKids,
23
26
  categories,
@@ -39,6 +42,8 @@ export default function useFilterBar() {
39
42
  guestsAdults,
40
43
  guestsKids,
41
44
  categories,
45
+ calendarRange,
46
+ setCalendarRange,
42
47
  setSelectedFilter,
43
48
  setGuestsAdults,
44
49
  setGuestsKids,
package/src/i18n.ts ADDED
@@ -0,0 +1,22 @@
1
+ import i18n from 'i18next'
2
+ import { initReactI18next } from 'react-i18next'
3
+
4
+ import enFilterBar from './locales/en/filterBar.json'
5
+ import fiFilterBar from './locales/fi/filterBar.json'
6
+
7
+ const urlParams = new URLSearchParams(window.location.search)
8
+ const localeFromUrl = urlParams.get('locale') || 'fi'
9
+ console.log(urlParams)
10
+ i18n.use(initReactI18next).init({
11
+ resources: {
12
+ en: { filterBar: enFilterBar },
13
+ fi: { filterBar: fiFilterBar },
14
+ },
15
+ lng: localeFromUrl,
16
+ fallbackLng: 'fi', // Fallback language
17
+ interpolation: {
18
+ escapeValue: false,
19
+ },
20
+ })
21
+
22
+ export default i18n
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import Button from "./components/Button";
2
- import FilterBar from "./components/FilterBar";
1
+ import Button from './components/Button'
2
+ import FilterBar from './components/FilterBar'
3
3
 
4
- export { Button, FilterBar };
4
+ export { Button, FilterBar }
@@ -0,0 +1,17 @@
1
+ {
2
+ "calendar": {
3
+ "startDate": "Start date",
4
+ "endDate": "End date"
5
+ },
6
+ "guests": {
7
+ "label": "Guests",
8
+ "title": "Guests",
9
+ "subtitle": "Who's coming?",
10
+ "adultsLabel": "Adults",
11
+ "kidsLabel": "kids"
12
+ },
13
+ "categories": {
14
+ "label": "Categories",
15
+ "title": "Category"
16
+ }
17
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "calendar": {
3
+ "startDate": "Aloitus päivämäärä",
4
+ "endDate": "Päättymis päivämäärä"
5
+ },
6
+ "guests": {
7
+ "label": "Vieraat",
8
+ "title": "Vieraat",
9
+ "subtitle": "Kuka saapuu?",
10
+ "adultsLabel": "Aikuiset",
11
+ "kidsLabel": "lapset"
12
+ },
13
+ "categories": {
14
+ "label": "Kategoriat",
15
+ "title": "Kategoria"
16
+ }
17
+ }
@@ -0,0 +1,13 @@
1
+ :root {
2
+ --primary-color: #3498db;
3
+ --font-size: 16px;
4
+ --box-shadow: 0px 6px 11px 0px #a7a4a480
5
+ }
6
+
7
+ * {
8
+ box-sizing: border-box;
9
+ }
10
+
11
+ html {
12
+ background-color: aqua;
13
+ }
@@ -0,0 +1,3 @@
1
+ html {
2
+ background-color: blue;
3
+ }
@@ -0,0 +1,3 @@
1
+ html {
2
+ background-color: red;
3
+ }
@@ -0,0 +1,5 @@
1
+ // cssModules.d.ts
2
+ declare module '*.css' {
3
+ const classes: { [key: string]: string }
4
+ export default classes
5
+ }
@@ -0,0 +1,32 @@
1
+ import { useEffect, useState } from 'react'
2
+
3
+ type ThemeProps = {
4
+ vendor?: string
5
+ }
6
+
7
+ export default function useTheme({ vendor }: ThemeProps) {
8
+ const [cssModule, setCssModule] = useState<any>(null)
9
+
10
+ useEffect(() => {
11
+ async function importCss() {
12
+ if (vendor === 'Kisakallio') {
13
+ const kisakallioCss = await import('./Kisakallio.css')
14
+ setCssModule(kisakallioCss.default)
15
+ } else if (vendor === 'Pajulahti') {
16
+ const pajulahtiCss = await import('./Pajulahti.css')
17
+ setCssModule(pajulahtiCss.default)
18
+ } else {
19
+ return
20
+ }
21
+ }
22
+
23
+ importCss()
24
+
25
+ // Clear the CSS module when the 'vendor' changes
26
+ return () => {
27
+ setCssModule(null)
28
+ }
29
+ }, [vendor])
30
+
31
+ return cssModule
32
+ }
package/tsconfig.json CHANGED
@@ -16,7 +16,13 @@
16
16
  "resolveJsonModule": true,
17
17
  "isolatedModules": true,
18
18
  "noEmit": true,
19
- "jsx": "react"
19
+ "jsx": "react",
20
+
21
+
22
+ "baseUrl": "./",
23
+ "paths": {
24
+ "src/*": ["src/*"]
25
+ }
20
26
  },
21
27
  "include": ["src"],
22
28
  "exclude": ["node_modules", "lib"]
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export default function Calendar(): React.JSX.Element;
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export default function Divider(): React.JSX.Element;
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export default function SelectButton({ label, onClick }: any): React.JSX.Element;
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export default function SubmitButton({ onClick }: any): React.JSX.Element;