@koine/react 1.0.5 → 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.
Files changed (159) hide show
  1. package/Alert/Alert.js +18 -0
  2. package/Alert/index.js +1 -0
  3. package/Animations/Reveal.js +17 -0
  4. package/Animations/Underline.js +15 -0
  5. package/Animations/index.js +3 -0
  6. package/Animations/useReveal.js +70 -0
  7. package/Autocomplete/AutocompleteDownshift.js +158 -0
  8. package/Autocomplete/AutocompleteDownshiftMultiselect.js +353 -0
  9. package/Autocomplete/AutocompleteMui.js +172 -0
  10. package/Autocomplete/AutocompleteReach.js +112 -0
  11. package/Autocomplete/components.js +89 -0
  12. package/Autocomplete/helpers.js +28 -0
  13. package/Autocomplete/index.js +3 -0
  14. package/Bg/BgColor.js +33 -0
  15. package/Bg/BgPhoto.js +59 -0
  16. package/Bg/BgSvg.js +15 -0
  17. package/Bg/index.js +3 -0
  18. package/Breadcrumbs/Breadcrumbs.js +70 -0
  19. package/Breadcrumbs/index.js +1 -0
  20. package/Buttons/Button.js +79 -0
  21. package/Buttons/ButtonComposite.d.ts +1 -1
  22. package/Buttons/ButtonComposite.js +53 -0
  23. package/Buttons/ButtonFab.js +8 -0
  24. package/Buttons/ButtonLink.js +16 -0
  25. package/Buttons/IconButton.js +19 -0
  26. package/Buttons/index.js +5 -0
  27. package/Calendar/CalendarDaygridCell.js +52 -0
  28. package/Calendar/CalendarDaygridNav.js +23 -0
  29. package/Calendar/CalendarDaygridTable.js +49 -0
  30. package/Calendar/CalendarLegend.js +12 -0
  31. package/Calendar/calendar-api-google.js +97 -0
  32. package/Calendar/index.js +6 -0
  33. package/Calendar/types.js +1 -0
  34. package/Calendar/useCalendar.js +166 -0
  35. package/Calendar/utils.js +197 -0
  36. package/Carousel/Carousel.js +378 -0
  37. package/Carousel/CarouselCss.js +39 -0
  38. package/Carousel/index.js +1 -0
  39. package/Collapsable/Collapsable.js +132 -0
  40. package/Collapsable/index.js +1 -0
  41. package/Debug/Debug.js +21 -0
  42. package/Debug/index.js +1 -0
  43. package/Dialog/Dialog.js +93 -0
  44. package/Dialog/index.js +1 -0
  45. package/Editor/Editor--tiptap.js +21 -0
  46. package/Editor/components.d.ts +1 -2
  47. package/Editor/components.js +28 -0
  48. package/Editor/index.js +1 -0
  49. package/Favicon/FaviconTags.js +14 -0
  50. package/Favicon/index.js +1 -0
  51. package/Forms/Checkbox/Checkbox.js +24 -0
  52. package/Forms/Checkbox/index.js +1 -0
  53. package/Forms/Feedback/Feedback.js +10 -0
  54. package/Forms/Feedback/index.js +1 -0
  55. package/Forms/Field/Field.js +61 -0
  56. package/Forms/Field/FieldControl.js +45 -0
  57. package/Forms/Field/FieldHint.js +6 -0
  58. package/Forms/Field/index.js +2 -0
  59. package/Forms/Form/Form.js +64 -0
  60. package/Forms/Form/index.js +1 -0
  61. package/Forms/Input/Input.js +25 -0
  62. package/Forms/Input/index.js +1 -0
  63. package/Forms/InputGroup/InputGroup.js +42 -0
  64. package/Forms/InputGroup/index.js +1 -0
  65. package/Forms/Label/Label.js +24 -0
  66. package/Forms/Label/index.js +1 -0
  67. package/Forms/Password/Password.js +32 -0
  68. package/Forms/Password/index.js +1 -0
  69. package/Forms/Radio/Radio.js +31 -0
  70. package/Forms/Radio/index.js +1 -0
  71. package/Forms/Switch/Switch.js +50 -0
  72. package/Forms/Switch/index.js +1 -0
  73. package/Forms/Textarea/Textarea.js +15 -0
  74. package/Forms/Textarea/TextareaRich.js +44 -0
  75. package/Forms/Textarea/index.js +2 -0
  76. package/Forms/Toggle/Toggle.js +79 -0
  77. package/Forms/Toggle/index.js +1 -0
  78. package/Forms/Toggle/useToggle.js +143 -0
  79. package/Forms/antispam.js +56 -0
  80. package/Forms/helpers.js +44 -0
  81. package/Forms/index.js +17 -0
  82. package/Forms/styles.js +60 -0
  83. package/Gauge/Gauge.js +102 -0
  84. package/Grid/Grid.js +79 -0
  85. package/Grid/index.js +1 -0
  86. package/Hamburger/Hamburger.js +55 -0
  87. package/Hamburger/index.js +1 -0
  88. package/Header/index.js +1 -0
  89. package/Header/useHeader.js +30 -0
  90. package/Hidden/Hidden.js +14 -0
  91. package/Hidden/index.js +1 -0
  92. package/Img/Img.js +34 -0
  93. package/Img/index.js +1 -0
  94. package/Link/Link.js +2 -0
  95. package/Link/LinkBlank.d.ts +1 -1
  96. package/Link/LinkBlank.js +28 -0
  97. package/Link/index.js +2 -0
  98. package/Menu/Menu.js +11 -0
  99. package/Menu/index.js +1 -0
  100. package/MenuItem/MenuItem.js +20 -0
  101. package/MenuItem/index.js +1 -0
  102. package/Meta/Meta.js +4 -0
  103. package/Meta/index.js +1 -0
  104. package/NoJs/NoJs.js +6 -0
  105. package/NoJs/index.js +1 -0
  106. package/Pagination/PaginationNav.js +87 -0
  107. package/Pagination/PaginationResults.js +10 -0
  108. package/Pagination/index.js +2 -0
  109. package/Pill/Pill.js +37 -0
  110. package/Pill/index.js +1 -0
  111. package/Progress/ProgressCircular.js +38 -0
  112. package/Progress/ProgressLinear.js +34 -0
  113. package/Progress/ProgressOverlay.js +40 -0
  114. package/Progress/index.js +3 -0
  115. package/Rating/Rating.js +93 -0
  116. package/Rating/index.js +45 -0
  117. package/Select/SelectDownshift.js +38 -0
  118. package/Select/components.js +20 -0
  119. package/Select/index.js +3 -0
  120. package/Sidebar/Sidebar.js +48 -0
  121. package/Sidebar/index.js +1 -0
  122. package/Spacing/Spacing.js +47 -0
  123. package/Spacing/index.js +1 -0
  124. package/Sticky/Sticky.js +220 -0
  125. package/Sticky/StickyCss.js +6 -0
  126. package/Sticky/index.js +1 -0
  127. package/Tabs/Tabs.js +67 -0
  128. package/Tabs/index.js +1 -0
  129. package/Typography/CopyPasteVisible.js +6 -0
  130. package/Typography/Native.js +47 -0
  131. package/Typography/ReadMore.js +71 -0
  132. package/Typography/TextLoop.js +45 -0
  133. package/Typography/TypeStairs.js +46 -0
  134. package/Typography/index.js +5 -0
  135. package/helpers/index.js +19 -0
  136. package/hooks/index.js +5 -0
  137. package/hooks/useDateLocale.js +30 -0
  138. package/hooks/useFocus.js +11 -0
  139. package/hooks/usePrevious.js +8 -0
  140. package/hooks/useTraceUpdate.js +20 -0
  141. package/hooks/useWindowSize.js +13 -0
  142. package/index.js +36 -0
  143. package/index.umd.js +232 -239
  144. package/package.json +15 -9
  145. package/styles/Body.js +17 -0
  146. package/styles/Global.js +50 -0
  147. package/styles/classed.js +11 -0
  148. package/styles/index.js +7 -0
  149. package/styles/media.js +150 -0
  150. package/styles/spacing.d.ts +6 -6
  151. package/styles/spacing.js +46 -0
  152. package/styles/styled.d.ts +2 -2
  153. package/styles/styled.js +27 -0
  154. package/styles/theme--vanilla.js +53 -0
  155. package/styles/theme.d.ts +0 -7
  156. package/styles/theme.js +38 -0
  157. package/types.js +1 -0
  158. package/typings.d.ts +21 -0
  159. package/index.esm.js +0 -9456
package/package.json CHANGED
@@ -1,17 +1,24 @@
1
1
  {
2
2
  "name": "@koine/react",
3
3
  "sideEffects": false,
4
- "version": "1.0.5",
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.esm.js",
13
+ "module": "./index.js",
7
14
  "typings": "./index.d.ts",
8
- "dependencies": {
15
+ "peerDependencies": {
9
16
  "styled-components": "^5.3.5",
10
17
  "framer-motion": "^6.2.9",
11
- "react": ">=17.0.2",
12
- "@mui/base": "^5.0.0-alpha.75",
13
- "@koine/utils": "1.0.5",
14
- "@react-icons/all-files": "^4.1.0",
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
+ `;
@@ -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;
@@ -0,0 +1,7 @@
1
+ export * from "./Body";
2
+ export * from "./Global";
3
+ export * from "./media";
4
+ export * from "./spacing";
5
+ export * from "./styled";
6
+ export * from "./theme";
7
+ export * from "./theme--vanilla";
@@ -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
+ }
@@ -1,13 +1,13 @@
1
- import type { Theme } from "./theme";
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 Theme["devices"];
8
+ export declare type SpacingDevices = keyof DefaultTheme["devices"];
9
9
  export declare type SpacingArgs = Parameters<typeof spacing>;
10
- export declare function spacing(this: Theme, size?: SpacingSize, factor?: SpacingFactor, property?: SpacingProperty, direction?: SpacingDirectionAxis, devices?: SpacingDevices[]): string;
11
- export declare function spacingTop(this: Theme, size?: SpacingSize, factor?: SpacingFactor, property?: SpacingProperty, devices?: SpacingDevices[]): string;
12
- export declare function spacingBottom(this: Theme, size?: SpacingSize, factor?: SpacingFactor, property?: SpacingProperty, devices?: SpacingDevices[]): string;
13
- export declare function spacingVertical(this: Theme, size?: SpacingSize, factor?: SpacingFactor, property?: SpacingProperty, devices?: SpacingDevices[]): string;
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
+ }
@@ -1,5 +1,5 @@
1
- import type { Theme } from "./theme";
2
- export declare function colStretch(this: Theme, direction: "left" | "right", color: keyof Readonly<Theme> | string): string;
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;
@@ -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;
@@ -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 {}