willba-component-library 0.0.35 → 0.0.37
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.
- package/lib/components/FilterBar/FilterBar.d.ts +7 -1
- package/lib/components/FilterBar/FilterBar.stories.d.ts +2 -2
- package/lib/i18n.d.ts +2 -0
- package/lib/index.d.ts +4 -1
- package/lib/index.esm.js +2625 -29
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +2624 -28
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +2624 -28
- package/lib/index.umd.js.map +1 -1
- package/lib/themes/useTheme.d.ts +5 -0
- package/package.json +5 -2
- package/rollup.config.mjs +24 -22
- package/src/components/FilterBar/FilterBar.css +2 -8
- package/src/components/FilterBar/FilterBar.stories.tsx +8 -9
- package/src/components/FilterBar/FilterBar.tsx +19 -5
- package/src/components/FilterBar/components/categories/Categories.tsx +5 -1
- package/src/components/FilterBar/components/guests/Guests.tsx +7 -4
- package/src/i18n.ts +26 -0
- package/src/index.ts +3 -3
- package/src/locales/en/filterBar.json +17 -0
- package/src/locales/fi/filterBar.json +17 -0
- package/src/themes/Default.css +13 -0
- package/src/themes/Kisakallio.css +3 -0
- package/src/themes/Pajulahti.css +3 -0
- package/src/themes/cssModules.d.ts +5 -0
- package/src/themes/useTheme.tsx +32 -0
- package/tsconfig.json +7 -1
- package/lib/components/FilterBar/components/Callendar.d.ts +0 -2
- package/lib/components/FilterBar/components/Divider.d.ts +0 -2
- package/lib/components/FilterBar/components/SelectButton.d.ts +0 -2
- package/lib/components/FilterBar/components/SubmitButton.d.ts +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "willba-component-library",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
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
|
-
"
|
|
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
|
|
2
|
-
import resolve from
|
|
3
|
-
import commonjs from
|
|
4
|
-
import typescript from
|
|
5
|
-
import postcss from
|
|
6
|
-
import dts from
|
|
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
|
|
12
|
-
const requireFile = createRequire(import.meta.url)
|
|
13
|
-
const packageJson = requireFile(
|
|
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:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
react: 'React',
|
|
18
|
+
'react-dom': 'ReactDOM',
|
|
19
|
+
'react-query': 'ReactQuery',
|
|
20
|
+
}
|
|
20
21
|
|
|
21
22
|
export default [
|
|
22
23
|
{
|
|
23
|
-
input:
|
|
24
|
+
input: 'src/index.ts',
|
|
24
25
|
output: [
|
|
25
26
|
{
|
|
26
27
|
file: packageJson.main,
|
|
27
|
-
format:
|
|
28
|
+
format: 'cjs',
|
|
28
29
|
sourcemap: true,
|
|
29
30
|
},
|
|
30
31
|
{
|
|
31
32
|
file: packageJson.module,
|
|
32
|
-
format:
|
|
33
|
+
format: 'esm',
|
|
33
34
|
sourcemap: true,
|
|
34
35
|
},
|
|
35
36
|
{
|
|
36
|
-
name:
|
|
37
|
+
name: 'WillbaComponentLibrary',
|
|
37
38
|
file: `lib/index.umd.js`,
|
|
38
|
-
format:
|
|
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: [
|
|
50
|
+
extensions: ['.css'],
|
|
50
51
|
}),
|
|
52
|
+
json(),
|
|
51
53
|
],
|
|
52
54
|
},
|
|
53
55
|
{
|
|
54
|
-
input:
|
|
55
|
-
output: [{ file:
|
|
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
|
+
]
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
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:
|
|
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
|
-
|
|
17
|
+
vendor: '',
|
|
19
18
|
},
|
|
20
|
-
}
|
|
19
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
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,10 +9,20 @@ 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,
|
|
@@ -30,19 +41,22 @@ export default function FilterBar() {
|
|
|
30
41
|
<div className="filter-bar">
|
|
31
42
|
<div className="filter-bar-header">
|
|
32
43
|
<SelectButton
|
|
33
|
-
label={'
|
|
44
|
+
label={t('calendar.startDate')}
|
|
34
45
|
onClick={() => handleSelectedFilter(1)}
|
|
35
46
|
/>
|
|
36
47
|
<Divider />
|
|
37
48
|
<SelectButton
|
|
38
|
-
label={'
|
|
49
|
+
label={t('calendar.endDate')}
|
|
39
50
|
onClick={() => handleSelectedFilter(2)}
|
|
40
51
|
/>
|
|
41
52
|
<Divider />
|
|
42
|
-
<SelectButton
|
|
53
|
+
<SelectButton
|
|
54
|
+
label={t('guests.label')}
|
|
55
|
+
onClick={() => handleSelectedFilter(3)}
|
|
56
|
+
/>
|
|
43
57
|
<Divider />
|
|
44
58
|
<SelectButton
|
|
45
|
-
label=
|
|
59
|
+
label={t('categories.label')}
|
|
46
60
|
onClick={() => handleSelectedFilter(4)}
|
|
47
61
|
/>
|
|
48
62
|
<SubmitButton onClick={handleSubmit} />
|
|
@@ -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>
|
|
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
17
|
<div className="filter-bar-guests">
|
|
15
|
-
<h3>
|
|
16
|
-
<p>
|
|
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>
|
|
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>
|
|
33
|
+
<span>{t('guests.kidsLabel')}</span>
|
|
31
34
|
<div>
|
|
32
35
|
<button onClick={decrementKids} disabled={guestsKids < 1}>
|
|
33
36
|
-
|
package/src/i18n.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
|
|
11
|
+
const userPreferredLanguage = navigator.language
|
|
12
|
+
console.log('User Preferred Language:', userPreferredLanguage)
|
|
13
|
+
|
|
14
|
+
i18n.use(initReactI18next).init({
|
|
15
|
+
resources: {
|
|
16
|
+
en: { filterBar: enFilterBar },
|
|
17
|
+
fi: { filterBar: fiFilterBar },
|
|
18
|
+
},
|
|
19
|
+
lng: localeFromUrl,
|
|
20
|
+
fallbackLng: 'fi', // Fallback language
|
|
21
|
+
interpolation: {
|
|
22
|
+
escapeValue: false,
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export default i18n
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Button from
|
|
2
|
-
import FilterBar from
|
|
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,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"]
|