@koine/react 1.0.3 → 1.0.8
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/Alert/Alert.js +18 -0
- package/Alert/index.js +1 -0
- package/Animations/Reveal.js +17 -0
- package/Animations/Underline.js +15 -0
- package/Animations/index.js +3 -0
- package/Animations/useReveal.js +70 -0
- package/Autocomplete/AutocompleteDownshift.js +158 -0
- package/Autocomplete/AutocompleteDownshiftMultiselect.js +353 -0
- package/Autocomplete/AutocompleteMui.js +172 -0
- package/Autocomplete/AutocompleteReach.js +112 -0
- package/Autocomplete/components.js +89 -0
- package/Autocomplete/helpers.js +28 -0
- package/Autocomplete/index.js +3 -0
- package/Bg/BgColor.js +33 -0
- package/Bg/BgPhoto.js +59 -0
- package/Bg/BgSvg.js +15 -0
- package/Bg/index.js +3 -0
- package/Breadcrumbs/Breadcrumbs.js +70 -0
- package/Breadcrumbs/index.js +1 -0
- package/Buttons/Button.js +79 -0
- package/Buttons/ButtonComposite.d.ts +1 -1
- package/Buttons/ButtonComposite.js +53 -0
- package/Buttons/ButtonFab.js +8 -0
- package/Buttons/ButtonLink.js +16 -0
- package/Buttons/IconButton.js +19 -0
- package/Buttons/index.js +5 -0
- package/Calendar/CalendarDaygridCell.js +52 -0
- package/Calendar/CalendarDaygridNav.js +23 -0
- package/Calendar/CalendarDaygridTable.js +49 -0
- package/Calendar/CalendarLegend.js +12 -0
- package/Calendar/calendar-api-google.js +97 -0
- package/Calendar/index.js +6 -0
- package/Calendar/types.js +1 -0
- package/Calendar/useCalendar.js +166 -0
- package/Calendar/utils.js +197 -0
- package/Carousel/Carousel.js +378 -0
- package/Carousel/CarouselCss.js +39 -0
- package/Carousel/index.js +1 -0
- package/Collapsable/Collapsable.js +132 -0
- package/Collapsable/index.js +1 -0
- package/Debug/Debug.js +21 -0
- package/Debug/index.js +1 -0
- package/Dialog/Dialog.js +93 -0
- package/Dialog/index.js +1 -0
- package/Editor/Editor--tiptap.js +21 -0
- package/Editor/components.d.ts +1 -2
- package/Editor/components.js +28 -0
- package/Editor/index.js +1 -0
- package/Favicon/FaviconTags.js +14 -0
- package/Favicon/index.js +1 -0
- package/Forms/Checkbox/Checkbox.js +24 -0
- package/Forms/Checkbox/index.js +1 -0
- package/Forms/Feedback/Feedback.js +10 -0
- package/Forms/Feedback/index.js +1 -0
- package/Forms/Field/Field.js +61 -0
- package/Forms/Field/FieldControl.js +45 -0
- package/Forms/Field/FieldHint.js +6 -0
- package/Forms/Field/index.js +2 -0
- package/Forms/Form/Form.js +64 -0
- package/Forms/Form/index.js +1 -0
- package/Forms/Input/Input.js +25 -0
- package/Forms/Input/index.js +1 -0
- package/Forms/InputGroup/InputGroup.js +42 -0
- package/Forms/InputGroup/index.js +1 -0
- package/Forms/Label/Label.js +24 -0
- package/Forms/Label/index.js +1 -0
- package/Forms/Password/Password.js +32 -0
- package/Forms/Password/index.js +1 -0
- package/Forms/Radio/Radio.js +31 -0
- package/Forms/Radio/index.js +1 -0
- package/Forms/Switch/Switch.js +50 -0
- package/Forms/Switch/index.js +1 -0
- package/Forms/Textarea/Textarea.js +15 -0
- package/Forms/Textarea/TextareaRich.js +44 -0
- package/Forms/Textarea/index.js +2 -0
- package/Forms/Toggle/Toggle.js +79 -0
- package/Forms/Toggle/index.js +1 -0
- package/Forms/Toggle/useToggle.js +143 -0
- package/Forms/antispam.js +56 -0
- package/Forms/helpers.js +44 -0
- package/Forms/index.js +17 -0
- package/Forms/styles.js +60 -0
- package/Gauge/Gauge.js +102 -0
- package/Grid/Grid.js +79 -0
- package/Grid/index.js +1 -0
- package/Hamburger/Hamburger.js +55 -0
- package/Hamburger/index.js +1 -0
- package/Header/index.js +1 -0
- package/Header/useHeader.js +30 -0
- package/Hidden/Hidden.js +14 -0
- package/Hidden/index.js +1 -0
- package/Img/Img.js +34 -0
- package/Img/index.js +1 -0
- package/Link/Link.js +2 -0
- package/Link/LinkBlank.d.ts +1 -1
- package/Link/LinkBlank.js +28 -0
- package/Link/index.js +2 -0
- package/Menu/Menu.js +11 -0
- package/Menu/index.js +1 -0
- package/MenuItem/MenuItem.js +20 -0
- package/MenuItem/index.js +1 -0
- package/Meta/Meta.js +4 -0
- package/Meta/index.js +1 -0
- package/NoJs/NoJs.js +6 -0
- package/NoJs/index.js +1 -0
- package/Pagination/PaginationNav.js +87 -0
- package/Pagination/PaginationResults.js +10 -0
- package/Pagination/index.js +2 -0
- package/Pill/Pill.js +37 -0
- package/Pill/index.js +1 -0
- package/Progress/ProgressCircular.js +38 -0
- package/Progress/ProgressLinear.js +34 -0
- package/Progress/ProgressOverlay.js +40 -0
- package/Progress/index.js +3 -0
- package/Rating/Rating.js +93 -0
- package/Rating/index.js +45 -0
- package/Select/SelectDownshift.js +38 -0
- package/Select/components.js +20 -0
- package/Select/index.js +3 -0
- package/Sidebar/Sidebar.js +48 -0
- package/Sidebar/index.js +1 -0
- package/Spacing/Spacing.js +47 -0
- package/Spacing/index.js +1 -0
- package/Sticky/Sticky.js +220 -0
- package/Sticky/StickyCss.js +6 -0
- package/Sticky/index.js +1 -0
- package/Tabs/Tabs.js +67 -0
- package/Tabs/index.js +1 -0
- package/Typography/CopyPasteVisible.js +6 -0
- package/Typography/Native.js +47 -0
- package/Typography/ReadMore.js +71 -0
- package/Typography/TextLoop.js +45 -0
- package/Typography/TypeStairs.js +46 -0
- package/Typography/index.js +5 -0
- package/helpers/index.js +19 -0
- package/hooks/index.js +5 -0
- package/hooks/useDateLocale.js +30 -0
- package/hooks/useFocus.js +11 -0
- package/hooks/usePrevious.js +8 -0
- package/hooks/useTraceUpdate.js +20 -0
- package/hooks/useWindowSize.js +13 -0
- package/index.js +36 -0
- package/index.umd.js +234 -257
- package/package.json +15 -9
- package/styles/Body.js +17 -0
- package/styles/Global.js +50 -0
- package/styles/classed.js +11 -0
- package/styles/index.js +7 -0
- package/styles/media.js +150 -0
- package/styles/spacing.d.ts +6 -6
- package/styles/spacing.js +46 -0
- package/styles/styled.d.ts +2 -2
- package/styles/styled.js +27 -0
- package/styles/theme--vanilla.js +53 -0
- package/styles/theme.d.ts +0 -7
- package/styles/theme.js +38 -0
- package/types.js +1 -0
- package/typings.d.ts +21 -0
- package/index.esm.js +0 -9472
package/package.json
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koine/react",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"@types/react": "^17.0.0 || ^18.0.0",
|
|
6
|
+
"@types/react-dom": "^17.0.0 || ^18.0.0",
|
|
7
|
+
"@types/react-is": "^17.0.0 || ^18.0.0",
|
|
8
|
+
"@types/styled-components": "^5.1.25",
|
|
9
|
+
"@types/yup": "^0.29.13"
|
|
10
|
+
},
|
|
11
|
+
"version": "1.0.8",
|
|
5
12
|
"main": "./index.umd.js",
|
|
6
|
-
"module": "./index.
|
|
13
|
+
"module": "./index.js",
|
|
7
14
|
"typings": "./index.d.ts",
|
|
8
|
-
"
|
|
15
|
+
"peerDependencies": {
|
|
9
16
|
"styled-components": "^5.3.5",
|
|
10
17
|
"framer-motion": "^6.2.9",
|
|
11
|
-
"react": "
|
|
12
|
-
"@mui/base": "^5.0.0-alpha.
|
|
13
|
-
"@koine/utils": "1.0.
|
|
14
|
-
"
|
|
18
|
+
"react": ">=17.0.2 || >=18.0.0",
|
|
19
|
+
"@mui/base": "^5.0.0-alpha.76",
|
|
20
|
+
"@koine/utils": "1.0.8",
|
|
21
|
+
"react-icons": "^4.3.1",
|
|
15
22
|
"date-fns": "^2.28.0",
|
|
16
23
|
"react-swipeable": "^6.2.1",
|
|
17
24
|
"@reach/disclosure": "^0.16.2",
|
|
@@ -23,6 +30,5 @@
|
|
|
23
30
|
"@n8tb1t/use-scroll-position": "^2.0.3",
|
|
24
31
|
"react-use": "^17.3.2",
|
|
25
32
|
"@reach/tabs": "^0.16.4"
|
|
26
|
-
}
|
|
27
|
-
"peerDependencies": {}
|
|
33
|
+
}
|
|
28
34
|
}
|
package/styles/Body.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
export const BodyRoot = styled.div `
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
min-height: 100vh;
|
|
6
|
+
`;
|
|
7
|
+
/**
|
|
8
|
+
* If you have background graphics to overlap you might need to add:
|
|
9
|
+
*
|
|
10
|
+
* ```css
|
|
11
|
+
* z-index: 1;
|
|
12
|
+
* position: relative;
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export const BodyMain = styled.main `
|
|
16
|
+
flex: 1;
|
|
17
|
+
`;
|
package/styles/Global.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createGlobalStyle } from "styled-components";
|
|
2
|
+
/**
|
|
3
|
+
* App global style
|
|
4
|
+
*
|
|
5
|
+
* For examples of what to do here take a look at [Bootstrap's reset](https://github.com/twbs/bootstrap/blob/main/scss/_reboot.scss)
|
|
6
|
+
* and similar.
|
|
7
|
+
*
|
|
8
|
+
* What we do here:
|
|
9
|
+
* - set the base font family on all possible elements including placeholders prevent Chrome showing a standard font when using the autofill feature
|
|
10
|
+
* - @see https://stackoverflow.com/a/60987373/1938970
|
|
11
|
+
* - set the base font size on all possible elements to prevent weird zooming on input fields on iPhone iOS devices.
|
|
12
|
+
* - @see https://www.warrenchandler.com/2019/04/02/stop-iphones-from-zooming-in-on-form-fields/
|
|
13
|
+
* - @see https://css-tricks.com/16px-or-larger-text-prevents-ios-form-zoom/
|
|
14
|
+
*/
|
|
15
|
+
export const stylesGlobal = `
|
|
16
|
+
body {
|
|
17
|
+
margin: 0;
|
|
18
|
+
padding: 0;
|
|
19
|
+
overflow-x: hidden;
|
|
20
|
+
overflow-y: scroll;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
body,
|
|
24
|
+
button,
|
|
25
|
+
input,
|
|
26
|
+
textarea,
|
|
27
|
+
select,
|
|
28
|
+
select:-webkit-autofill::first-line,
|
|
29
|
+
input:-webkit-autofill::first-line {
|
|
30
|
+
font-family: var(--font), -apple-system, BlinkMacSystemFont, "Segoe UI",
|
|
31
|
+
Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
|
|
32
|
+
sans-serif;
|
|
33
|
+
font-size: var(--fontSize);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
html {
|
|
37
|
+
box-sizing: border-box;
|
|
38
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
39
|
+
scroll-behavior: smooth;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
*,
|
|
44
|
+
*:before,
|
|
45
|
+
*:after {
|
|
46
|
+
box-sizing: inherit;
|
|
47
|
+
-webkit-tap-highlight-color: transparent;
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
export const StylesGlobal = createGlobalStyle `${stylesGlobal}`;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Adapted (removed `classnames` dependency) from:
|
|
4
|
+
* @see https://daily.dev/blog/my-tailwind-css-utility-function-for-creating-reusable-react-components-typescript-support
|
|
5
|
+
*/
|
|
6
|
+
function classed(type, ...className) {
|
|
7
|
+
return function Classed(props) {
|
|
8
|
+
return createElement(type, Object.assign(Object.assign({}, props), { className: [(props === null || props === void 0 ? void 0 : props.className) || ""].concat(className).join(" ") }));
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export default classed;
|
package/styles/index.js
ADDED
package/styles/media.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
import { useTheme, breakpoints } from "./theme";
|
|
3
|
+
export const { min, max, up, down, between, only } = generateMediaQueries(breakpoints);
|
|
4
|
+
export function useMedia(media) {
|
|
5
|
+
const { breakpoints } = useTheme();
|
|
6
|
+
const [matches, setMatches] = useState(false);
|
|
7
|
+
const [direction = "min", breakpoint] = media.split(":");
|
|
8
|
+
let px = breakpoints[breakpoint];
|
|
9
|
+
if (direction === "max") {
|
|
10
|
+
px = px - 0.02;
|
|
11
|
+
}
|
|
12
|
+
const query = `(${direction}-width: ${px}px)`;
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const mq = window.matchMedia(query);
|
|
15
|
+
const handleChange = (event) => {
|
|
16
|
+
setMatches(event.matches);
|
|
17
|
+
};
|
|
18
|
+
setMatches(mq.matches);
|
|
19
|
+
// Safari < 14 can't use addEventListener on a MediaQueryList
|
|
20
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#Browser_compatibility
|
|
21
|
+
if (!mq.addEventListener) {
|
|
22
|
+
// Update the state whenever the media query match state changes
|
|
23
|
+
mq.addListener(handleChange);
|
|
24
|
+
// Clean up on unmount and if the query changes
|
|
25
|
+
return () => {
|
|
26
|
+
mq.removeListener(handleChange);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
mq.addEventListener("change", handleChange);
|
|
30
|
+
return () => {
|
|
31
|
+
mq.removeEventListener("change", handleChange);
|
|
32
|
+
};
|
|
33
|
+
}, [query]);
|
|
34
|
+
return matches;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Generate media queries helpers
|
|
38
|
+
*
|
|
39
|
+
* Usage:
|
|
40
|
+
* ```jsx
|
|
41
|
+
* import { generateMediaQueries } from "@koine/react";
|
|
42
|
+
*
|
|
43
|
+
* export const breakpoints = {
|
|
44
|
+
* xs: 0,
|
|
45
|
+
* sm: 440,
|
|
46
|
+
* md: 768,
|
|
47
|
+
* lg: 1024,
|
|
48
|
+
* xl: 1368,
|
|
49
|
+
* xxl: 1690,
|
|
50
|
+
* } as const;
|
|
51
|
+
*
|
|
52
|
+
* export const { min, max, up, down, between, only } = generateMediaQueries(breakpoints);
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* Consider the following syntaxes, using normal CSS is just slightly
|
|
56
|
+
* longer but it aovid js imports, reduce the js overhead and improve CSS
|
|
57
|
+
* highlighting in the editor.
|
|
58
|
+
*
|
|
59
|
+
* Even if we would reduce the function signature to the bare minimum the advantage
|
|
60
|
+
* in terms of typing would not be much, also loosing in readability.
|
|
61
|
+
*
|
|
62
|
+
* ```css
|
|
63
|
+
* // but unfortunately this does not work
|
|
64
|
+
* @media (min-width: var(--b-sm)) {}
|
|
65
|
+
* @media (min-width: 480px) {}
|
|
66
|
+
*
|
|
67
|
+
* ${media("min", "sm")} {}
|
|
68
|
+
* ${mediaMin("sm")} {}
|
|
69
|
+
* ${min.sm} {}
|
|
70
|
+
* ${p => p.theme.min.sm}``
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* Related projects:
|
|
74
|
+
* @see https://github.com/mg901/styled-breakpoints
|
|
75
|
+
* @see https://github.com/morajabi/styled-media-query
|
|
76
|
+
*
|
|
77
|
+
* @see https://www.w3.org/TR/mediaqueries-5/#custom-mq The spec would allow for
|
|
78
|
+
* something like this syntax
|
|
79
|
+
*
|
|
80
|
+
* ```css
|
|
81
|
+
* @custom-media --narrow-window (max-width: 30em);
|
|
82
|
+
* @media (--narrow-window) {}
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export function generateMediaQueries(breakpoints) {
|
|
86
|
+
const temp = Object.keys(breakpoints).map((key) => {
|
|
87
|
+
const br = key;
|
|
88
|
+
return [br, breakpoints[br]];
|
|
89
|
+
});
|
|
90
|
+
const sortedKeys = temp.sort((a, b) => a[1] - b[1]).map((item) => item[0]);
|
|
91
|
+
const getNext = (breakpoint) => {
|
|
92
|
+
const index = sortedKeys.indexOf(breakpoint);
|
|
93
|
+
return sortedKeys[index + 1];
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* It behaves the same as `@media (min-width: ${value}px)`
|
|
97
|
+
* where value is the given breakpoint value.
|
|
98
|
+
* For ease of use this can be used both as a function `min("md")` and as an
|
|
99
|
+
* object literal `min.md`.
|
|
100
|
+
*/ // @ts-expect-error FIXME: at some point
|
|
101
|
+
const min = (br) => `@media (min-width: ${breakpoints[br]}px)`;
|
|
102
|
+
/**
|
|
103
|
+
* It behaves the same as `@media (max-width: ${value}px)`
|
|
104
|
+
* where value is the given breakpoint value.
|
|
105
|
+
* For ease of use this can be used both as a function `max("md")` and as an
|
|
106
|
+
* object literal `max.md`.
|
|
107
|
+
*/ // @ts-expect-error FIXME: at some point
|
|
108
|
+
const max = (br) => `@media (max-width: ${breakpoints[br] - 0.02}px)`;
|
|
109
|
+
for (const br in breakpoints) {
|
|
110
|
+
const _br = br;
|
|
111
|
+
min[_br] = `@media (min-width: ${breakpoints[_br]}px)`;
|
|
112
|
+
max[_br] = `@media (max-width: ${breakpoints[_br] - 0.02}px)`;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* It behaves the same as `min`
|
|
116
|
+
* @inheritdoc {max}
|
|
117
|
+
*/
|
|
118
|
+
const up = min;
|
|
119
|
+
/**
|
|
120
|
+
* It behaves similarly to `max` but you will use the "next" breakpoint,
|
|
121
|
+
* specifying CSS that will apply from the given breakpoint and down.
|
|
122
|
+
*/
|
|
123
|
+
const down = (br) => {
|
|
124
|
+
const brNext = getNext(br);
|
|
125
|
+
// TODO: if br does not exists otherwise throw Error
|
|
126
|
+
return brNext && `@media (max-width: ${breakpoints[brNext] - 0.02}px)`;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Media query between the two given breakpoints
|
|
130
|
+
*/
|
|
131
|
+
const between = (br1, br2) => {
|
|
132
|
+
return `@media (min-width: ${breakpoints[br1]}px) and (max-width: ${breakpoints[br2] - 0.02}px)`;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Media query to apply from the given breakpoint until the next, just for its
|
|
136
|
+
* full range
|
|
137
|
+
*/
|
|
138
|
+
const only = (br) => {
|
|
139
|
+
const brNext = getNext(br);
|
|
140
|
+
return brNext ? between(br, brNext) : min(br);
|
|
141
|
+
};
|
|
142
|
+
return {
|
|
143
|
+
min,
|
|
144
|
+
max,
|
|
145
|
+
up,
|
|
146
|
+
down,
|
|
147
|
+
between,
|
|
148
|
+
only,
|
|
149
|
+
};
|
|
150
|
+
}
|
package/styles/spacing.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DefaultTheme } from "styled-components";
|
|
2
2
|
export declare type SpacingSize = "sm" | "md" | "lg";
|
|
3
3
|
export declare type SpacingProperty = "padding" | "margin";
|
|
4
4
|
/** @default 1 */
|
|
5
5
|
export declare type SpacingFactor = number;
|
|
6
6
|
export declare type SpacingDirection = "top" | "bottom";
|
|
7
7
|
export declare type SpacingDirectionAxis = "vertical" | SpacingDirection;
|
|
8
|
-
export declare type SpacingDevices = keyof
|
|
8
|
+
export declare type SpacingDevices = keyof DefaultTheme["devices"];
|
|
9
9
|
export declare type SpacingArgs = Parameters<typeof spacing>;
|
|
10
|
-
export declare function spacing(this:
|
|
11
|
-
export declare function spacingTop(this:
|
|
12
|
-
export declare function spacingBottom(this:
|
|
13
|
-
export declare function spacingVertical(this:
|
|
10
|
+
export declare function spacing(this: DefaultTheme, size?: SpacingSize, factor?: SpacingFactor, property?: SpacingProperty, direction?: SpacingDirectionAxis, devices?: SpacingDevices[]): string;
|
|
11
|
+
export declare function spacingTop(this: DefaultTheme, size?: SpacingSize, factor?: SpacingFactor, property?: SpacingProperty, devices?: SpacingDevices[]): string;
|
|
12
|
+
export declare function spacingBottom(this: DefaultTheme, size?: SpacingSize, factor?: SpacingFactor, property?: SpacingProperty, devices?: SpacingDevices[]): string;
|
|
13
|
+
export declare function spacingVertical(this: DefaultTheme, size?: SpacingSize, factor?: SpacingFactor, property?: SpacingProperty, devices?: SpacingDevices[]): string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
function _spacing(theme, size = "md", factor = 1, property = "padding", direction = "top", devices = ["mobile", "tablet", "desktop"]) {
|
|
2
|
+
const { breakpoints, devices: DEVICES, spaces: SPACES } = theme;
|
|
3
|
+
let css = "";
|
|
4
|
+
const prop = `${property}-${direction}`;
|
|
5
|
+
if (devices === ["mobile"]) {
|
|
6
|
+
css += `@media(max-width: ${breakpoints[DEVICES.mobile]}px){
|
|
7
|
+
${prop}: ${SPACES["mobile"][size] * factor}px;
|
|
8
|
+
}`;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
for (let index = 0; index < devices.length; index++) {
|
|
12
|
+
const device = devices[index];
|
|
13
|
+
if (device === "mobile") {
|
|
14
|
+
css += `${prop}: ${SPACES[device][size] * factor}px;`;
|
|
15
|
+
}
|
|
16
|
+
else if (device === "tablet") {
|
|
17
|
+
css += `@media(min-width: ${breakpoints[DEVICES.tablet]}px){
|
|
18
|
+
${prop}: ${SPACES["tablet"][size] * factor}px;
|
|
19
|
+
}`;
|
|
20
|
+
}
|
|
21
|
+
else if (device === "desktop") {
|
|
22
|
+
css += `@media(min-width: ${breakpoints[DEVICES.desktop]}px){
|
|
23
|
+
${prop}: ${SPACES["desktop"][size] * factor}px;
|
|
24
|
+
}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return css;
|
|
29
|
+
}
|
|
30
|
+
export function spacing(size, factor, property, direction, devices) {
|
|
31
|
+
if (direction === "vertical") {
|
|
32
|
+
return (_spacing(this, size, factor, property, "top", devices) +
|
|
33
|
+
_spacing(this, size, factor, property, "bottom", devices));
|
|
34
|
+
}
|
|
35
|
+
return _spacing(this, size, factor, property, direction, devices);
|
|
36
|
+
}
|
|
37
|
+
export function spacingTop(size, factor, property, devices) {
|
|
38
|
+
return _spacing(this, size, factor, property, "top", devices);
|
|
39
|
+
}
|
|
40
|
+
export function spacingBottom(size, factor, property, devices) {
|
|
41
|
+
return _spacing(this, size, factor, property, "bottom", devices);
|
|
42
|
+
}
|
|
43
|
+
export function spacingVertical(size, factor, property, devices) {
|
|
44
|
+
return (_spacing(this, size, factor, property, "top", devices) +
|
|
45
|
+
_spacing(this, size, factor, property, "bottom", devices));
|
|
46
|
+
}
|
package/styles/styled.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare function colStretch(
|
|
1
|
+
import React from "react";
|
|
2
|
+
export declare function colStretch(direction: "left" | "right", bg: React.CSSProperties["background"]): string;
|
|
3
3
|
/** @see https://caniuse.com/?search=inset */
|
|
4
4
|
export declare const inset0 = "top:0;left:0;right:0;bottom:0;";
|
|
5
5
|
export declare const overlay: string;
|
package/styles/styled.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function colStretch(direction, bg) {
|
|
2
|
+
return `
|
|
3
|
+
background: ${bg};
|
|
4
|
+
position: relative;
|
|
5
|
+
|
|
6
|
+
&:before{
|
|
7
|
+
z-index: -1;
|
|
8
|
+
content: '';
|
|
9
|
+
position: absolute;
|
|
10
|
+
right: ${direction === "left" ? "100%" : "-100vw"};
|
|
11
|
+
left: ${direction === "right" ? "100%" : "-100vw"};
|
|
12
|
+
top: 0;
|
|
13
|
+
bottom: 0;
|
|
14
|
+
background: ${bg};
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
}
|
|
18
|
+
/** @see https://caniuse.com/?search=inset */
|
|
19
|
+
export const inset0 = `top:0;left:0;right:0;bottom:0;`;
|
|
20
|
+
export const overlay = `position: absolute;${inset0}`;
|
|
21
|
+
export const centered = `display: flex;align-items: center;justify-content: center;`;
|
|
22
|
+
export const ellipsis = `overflow: hidden;text-overflow: ellipsis;white-space: nowrap;`;
|
|
23
|
+
/**
|
|
24
|
+
* @see import("@mui/utils").visuallyHidden https://github.com/mui-org/material-ui/blob/master/packages/mui-utils/src/visuallyHidden.ts
|
|
25
|
+
*/
|
|
26
|
+
export const invisible = `border: 0;clip: rect(0 0 0 0);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;white-space: nowrap;width: 1px;`;
|
|
27
|
+
export const stateFocus = `outline: 0px;box-shadow: 0 0 0 0.2rem rgba(200, 200, 200, 0.25);`;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useState } from "react";
|
|
3
|
+
import { isBrowser, setCookie, parseCookie } from "@koine/utils";
|
|
4
|
+
import { useMount, useUpdateEffect } from "react-use";
|
|
5
|
+
export const THEME_KEY = "theme";
|
|
6
|
+
export const THEME_DEFAULT = "light";
|
|
7
|
+
export const getInitialThemeFromRequest = (cookie) => {
|
|
8
|
+
if (cookie) {
|
|
9
|
+
const parsed = parseCookie(cookie);
|
|
10
|
+
return parsed === null || parsed === void 0 ? void 0 : parsed.theme;
|
|
11
|
+
}
|
|
12
|
+
return THEME_DEFAULT;
|
|
13
|
+
};
|
|
14
|
+
export const getInitialThemeFromClient = () => {
|
|
15
|
+
if (typeof window !== "undefined" && window.localStorage) {
|
|
16
|
+
const storedPrefs = window.localStorage.getItem(THEME_KEY);
|
|
17
|
+
if (typeof storedPrefs === "string") {
|
|
18
|
+
return storedPrefs;
|
|
19
|
+
}
|
|
20
|
+
const userMedia = window.matchMedia("(prefers-color-scheme: dark)");
|
|
21
|
+
if (userMedia.matches) {
|
|
22
|
+
return "dark";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return THEME_DEFAULT;
|
|
26
|
+
};
|
|
27
|
+
export const ThemeVanillaContext = createContext({
|
|
28
|
+
theme: "light",
|
|
29
|
+
setTheme: undefined,
|
|
30
|
+
});
|
|
31
|
+
export const ThemeVanillaProvider = ({ initialTheme, children, }) => {
|
|
32
|
+
const [theme, setTheme] = useState(initialTheme);
|
|
33
|
+
const rawSetTheme = (rawTheme) => {
|
|
34
|
+
if (!rawTheme || !isBrowser) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const root = window.document.documentElement;
|
|
38
|
+
const isDark = rawTheme === "dark";
|
|
39
|
+
root.classList.remove(isDark ? "light" : "dark");
|
|
40
|
+
root.classList.add(rawTheme);
|
|
41
|
+
localStorage.setItem(THEME_KEY, rawTheme);
|
|
42
|
+
setCookie(THEME_KEY, rawTheme);
|
|
43
|
+
};
|
|
44
|
+
useMount(() => {
|
|
45
|
+
const theme = getInitialThemeFromClient();
|
|
46
|
+
setTheme(theme);
|
|
47
|
+
rawSetTheme(theme);
|
|
48
|
+
});
|
|
49
|
+
useUpdateEffect(() => {
|
|
50
|
+
rawSetTheme(theme);
|
|
51
|
+
}, [theme]);
|
|
52
|
+
return (_jsx(ThemeVanillaContext.Provider, Object.assign({ value: { theme, setTheme } }, { children: children })));
|
|
53
|
+
};
|
package/styles/theme.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { spacing, spacingTop, spacingBottom, spacingVertical } from "./spacing";
|
|
2
|
-
import { colStretch } from "./styled";
|
|
3
1
|
export declare type Breakpoint = "xs" | "sm" | "md" | "lg" | "xl" | "xxl";
|
|
4
2
|
export declare type Breakpoints = Record<Breakpoint, number>;
|
|
5
3
|
/**
|
|
@@ -74,11 +72,6 @@ export declare type Theme = {
|
|
|
74
72
|
/** @default [70, 70] */
|
|
75
73
|
logoWidthSticky: [number, number];
|
|
76
74
|
};
|
|
77
|
-
spacing: typeof spacing;
|
|
78
|
-
spacingTop: typeof spacingTop;
|
|
79
|
-
spacingBottom: typeof spacingBottom;
|
|
80
|
-
spacingVertical: typeof spacingVertical;
|
|
81
|
-
colStretch: typeof colStretch;
|
|
82
75
|
};
|
|
83
76
|
export declare type ThemeOptions = {
|
|
84
77
|
maxWidth?: number;
|
package/styles/theme.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useTheme as _useTheme } from "styled-components";
|
|
2
|
+
const DEFAULT_BREAKPOINTS = {
|
|
3
|
+
xs: 0,
|
|
4
|
+
sm: 440,
|
|
5
|
+
md: 768,
|
|
6
|
+
lg: 1024,
|
|
7
|
+
xl: 1368,
|
|
8
|
+
xxl: 1690,
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* You can override the default breakpoints through the .env variable
|
|
12
|
+
*
|
|
13
|
+
* FIXME: find a better way to configure it, the problem is that we use the media
|
|
14
|
+
* queries within this pre-compiled library and thrught it was better to avoid
|
|
15
|
+
* using theming props for a more ergonomic usage.
|
|
16
|
+
*
|
|
17
|
+
* ```.env
|
|
18
|
+
* BREAKPOINTS=xs:0,sm:440,md:768,lg:1024,xl:1368,xxl:1690
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const breakpoints = process.env["BREAKPOINTS"]
|
|
22
|
+
? process.env["BREAKPOINTS"].split(",").reduce((map, pair) => {
|
|
23
|
+
const [key, value] = pair.split(":");
|
|
24
|
+
map[key] = parseFloat(value);
|
|
25
|
+
return map;
|
|
26
|
+
}, {})
|
|
27
|
+
: DEFAULT_BREAKPOINTS;
|
|
28
|
+
const themeDefault = {
|
|
29
|
+
maxWidth: breakpoints.xxl,
|
|
30
|
+
breakpoints,
|
|
31
|
+
devices: {
|
|
32
|
+
mobile: "sm",
|
|
33
|
+
tablet: "md",
|
|
34
|
+
desktop: "lg",
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
export const createTheme = (options) => (Object.assign(Object.assign({}, themeDefault), options));
|
|
38
|
+
export const useTheme = _useTheme;
|
package/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/typings.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "styled-components";
|
|
2
|
+
// import type {} from "styled-components/cssprop"; // for `css` prop
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Styled components utility types
|
|
6
|
+
*/
|
|
7
|
+
type Theme = import("./styles/theme").Theme;
|
|
8
|
+
|
|
9
|
+
declare module "styled-components" {
|
|
10
|
+
// extends the global DefaultTheme with our ThemeType.
|
|
11
|
+
export interface DefaultTheme extends Theme {
|
|
12
|
+
maxWidth: number;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Types specifically related to `@koine/react` exposed on the global unique
|
|
18
|
+
* namespace `Koine`. Most of the types here should be prefixed by `React`, e.g.
|
|
19
|
+
* `ReactSomeFeature` accessible anywhere from `Koine.ReactSomeFeature`
|
|
20
|
+
*/
|
|
21
|
+
declare namespace Koine {}
|