@biblioteksentralen/react 1.0.0-beta.1
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/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-test.log +13 -0
- package/.turbo/turbo-type-check.log +4 -0
- package/LICENSE +21 -0
- package/dist/BiblioteksentralenProvider.d.ts +8 -0
- package/dist/BiblioteksentralenProvider.js +8 -0
- package/dist/components/Alert.d.ts +11 -0
- package/dist/components/Alert.js +52 -0
- package/dist/components/Button.d.ts +12 -0
- package/dist/components/Button.js +2 -0
- package/dist/components/ConditionalWrapper.d.ts +13 -0
- package/dist/components/ConditionalWrapper.js +8 -0
- package/dist/components/ErrorBoundary.d.ts +19 -0
- package/dist/components/ErrorBoundary.js +64 -0
- package/dist/components/HashLinkTarget.d.ts +14 -0
- package/dist/components/HashLinkTarget.js +28 -0
- package/dist/components/HideWithCSS.d.ts +10 -0
- package/dist/components/HideWithCSS.js +31 -0
- package/dist/components/Input.d.ts +15 -0
- package/dist/components/Input.js +37 -0
- package/dist/components/Link.d.ts +12 -0
- package/dist/components/Link.js +2 -0
- package/dist/components/VisuallyHidden.d.ts +6 -0
- package/dist/components/VisuallyHidden.js +41 -0
- package/dist/components/withErrorBoundary.d.ts +2 -0
- package/dist/components/withErrorBoundary.js +17 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/styles/chakraTheme/ButtonStyles.d.ts +3 -0
- package/dist/styles/chakraTheme/ButtonStyles.js +49 -0
- package/dist/styles/chakraTheme/CheckboxStyles.d.ts +4 -0
- package/dist/styles/chakraTheme/CheckboxStyles.js +12 -0
- package/dist/styles/chakraTheme/ContainerStyles.d.ts +2 -0
- package/dist/styles/chakraTheme/ContainerStyles.js +5 -0
- package/dist/styles/chakraTheme/HeadingStyles.d.ts +2 -0
- package/dist/styles/chakraTheme/HeadingStyles.js +5 -0
- package/dist/styles/chakraTheme/InputStyles.d.ts +2 -0
- package/dist/styles/chakraTheme/InputStyles.js +39 -0
- package/dist/styles/chakraTheme/LinkStyles.d.ts +3 -0
- package/dist/styles/chakraTheme/LinkStyles.js +17 -0
- package/dist/styles/chakraTheme/ModalStyles.d.ts +2 -0
- package/dist/styles/chakraTheme/ModalStyles.js +10 -0
- package/dist/styles/chakraTheme/SpinnerStyles.d.ts +2 -0
- package/dist/styles/chakraTheme/SpinnerStyles.js +15 -0
- package/dist/styles/chakraTheme/biblioteksentralenChakraTheme.d.ts +2 -0
- package/dist/styles/chakraTheme/biblioteksentralenChakraTheme.js +32 -0
- package/dist/styles/chakraTheme/sizes.d.ts +8 -0
- package/dist/styles/chakraTheme/sizes.js +9 -0
- package/package.json +42 -0
- package/src/BiblioteksentralenProvider.tsx +16 -0
- package/src/components/Alert.tsx +60 -0
- package/src/components/Button.tsx +11 -0
- package/src/components/ConditionalWrapper.tsx +13 -0
- package/src/components/ErrorBoundary.tsx +60 -0
- package/src/components/HashLinkTarget.tsx +51 -0
- package/src/components/HideWithCSS.tsx +22 -0
- package/src/components/Input.tsx +37 -0
- package/src/components/Link.tsx +10 -0
- package/src/components/VisuallyHidden.tsx +36 -0
- package/src/components/withErrorBoundary.tsx +10 -0
- package/src/index.ts +14 -0
- package/src/styles/chakraTheme/ButtonStyles.ts +55 -0
- package/src/styles/chakraTheme/CheckboxStyles.ts +19 -0
- package/src/styles/chakraTheme/ContainerStyles.ts +7 -0
- package/src/styles/chakraTheme/HeadingStyles.ts +7 -0
- package/src/styles/chakraTheme/InputStyles.ts +41 -0
- package/src/styles/chakraTheme/LinkStyles.ts +23 -0
- package/src/styles/chakraTheme/ModalStyles.ts +12 -0
- package/src/styles/chakraTheme/SpinnerStyles.ts +13 -0
- package/src/styles/chakraTheme/biblioteksentralenChakraTheme.ts +34 -0
- package/src/styles/chakraTheme/sizes.ts +10 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
> @biblioteksentralen/react@1.0.0-beta.1 test /Users/jorgenfulsebakke/repos/js-utils/packages/react
|
|
3
|
+
> vitest --watch=false
|
|
4
|
+
|
|
5
|
+
[33mThe CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.[39m
|
|
6
|
+
|
|
7
|
+
RUN v1.1.0 /Users/jorgenfulsebakke/repos/js-utils/packages/react
|
|
8
|
+
|
|
9
|
+
include: **/*.{test,spec}.?(c|m)[jt]s?(x)
|
|
10
|
+
exclude: **/node_modules/**, **/dist/**, **/cypress/**, **/.{idea,git,cache,output,temp}/**, **/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*
|
|
11
|
+
watch exclude: **/node_modules/**, **/dist/**
|
|
12
|
+
No test files found, exiting with code 0
|
|
13
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Biblioteksentralen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ChakraTheme } from "@chakra-ui/react";
|
|
2
|
+
import React, { ReactNode } from "react";
|
|
3
|
+
interface Props {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
customTheme?: Partial<ChakraTheme>;
|
|
6
|
+
}
|
|
7
|
+
export declare const BiblioteksentralenProvider: (props: Props) => React.JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ChakraProvider, extendTheme } from "@chakra-ui/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { biblioteksentralenChakraTheme } from "./styles/chakraTheme/biblioteksentralenChakraTheme";
|
|
4
|
+
var emptyTheme = {};
|
|
5
|
+
export var BiblioteksentralenProvider = function (props) {
|
|
6
|
+
var _a;
|
|
7
|
+
return (React.createElement(ChakraProvider, { theme: extendTheme(biblioteksentralenChakraTheme, (_a = props.customTheme) !== null && _a !== void 0 ? _a : emptyTheme) }, props.children));
|
|
8
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AlertProps, FlexProps } from "@chakra-ui/react";
|
|
2
|
+
import React, { ReactNode } from "react";
|
|
3
|
+
type Status = Exclude<AlertProps["status"], undefined | "loading">;
|
|
4
|
+
type Variants = "inline";
|
|
5
|
+
interface Props extends FlexProps {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
status: Status;
|
|
8
|
+
variant?: Variants;
|
|
9
|
+
}
|
|
10
|
+
export declare function Alert({ status, children, variant, ...rest }: Props): React.JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import { BsCheckCircle, BsExclamationCircle, BsXCircle, InformationIcon } from "@biblioteksentralen/icons";
|
|
24
|
+
import { colors } from "@biblioteksentralen/utils";
|
|
25
|
+
import { Box, Flex } from "@chakra-ui/react";
|
|
26
|
+
import React from "react";
|
|
27
|
+
var colorLookup = {
|
|
28
|
+
info: { bg: colors.lightBlue, color: colors.accentBlueMedium },
|
|
29
|
+
warning: { bg: colors.alertYellow, color: colors.statusYellow },
|
|
30
|
+
success: { bg: "green.100", color: "green.600" },
|
|
31
|
+
error: { bg: colors.alertRed, color: colors.statusRed },
|
|
32
|
+
};
|
|
33
|
+
var iconLookup = {
|
|
34
|
+
info: React.createElement(InformationIcon, { role: "img", "aria-label": "Informasjon" }),
|
|
35
|
+
warning: React.createElement(BsExclamationCircle, { role: "img", "aria-label": "Advarsel" }),
|
|
36
|
+
success: React.createElement(BsCheckCircle, { role: "img", "aria-label": "Suksess" }),
|
|
37
|
+
error: React.createElement(BsXCircle, { role: "img", "aria-label": "Feil" }),
|
|
38
|
+
};
|
|
39
|
+
var variantStyles = {
|
|
40
|
+
inline: {
|
|
41
|
+
borderColor: "transparent",
|
|
42
|
+
backgroundColor: "transparent",
|
|
43
|
+
padding: "0",
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
export function Alert(_a) {
|
|
47
|
+
var status = _a.status, children = _a.children, variant = _a.variant, rest = __rest(_a, ["status", "children", "variant"]);
|
|
48
|
+
var colors = colorLookup[status];
|
|
49
|
+
return (React.createElement(Flex, __assign({ role: "alert", flexWrap: "wrap", alignItems: "center", gridGap: "0.5rem 1rem", background: "white", border: "0.1rem solid", borderColor: colors.color, backgroundColor: colors.bg, padding: "0.75rem", borderRadius: "0.3rem" }, (variant ? variantStyles[variant] : {}), rest),
|
|
50
|
+
React.createElement(Box, { color: colors.color, flex: "0 0", marginLeft: "auto", marginRight: "auto", lineHeight: "1", fontSize: "1.5em" }, iconLookup[status]),
|
|
51
|
+
React.createElement(Box, { flex: "1" }, children)));
|
|
52
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ButtonProps, ComponentWithAs } from "@chakra-ui/react";
|
|
2
|
+
import { Modify } from "@biblioteksentralen/types";
|
|
3
|
+
import { CustomButtonVariants } from "../styles/chakraTheme/ButtonStyles";
|
|
4
|
+
/**
|
|
5
|
+
* Re-exporting chackras Button with a customised types
|
|
6
|
+
* This causes both chakras native variants and our home-made variants to show up in auto-complete
|
|
7
|
+
*/
|
|
8
|
+
type ButtonVariants = ButtonProps["variant"] | CustomButtonVariants;
|
|
9
|
+
export declare const Button: ComponentWithAs<"button", Modify<ButtonProps, {
|
|
10
|
+
variant?: ButtonVariants;
|
|
11
|
+
}>>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FunctionComponent, ReactNode } from "react";
|
|
2
|
+
type Props = {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
wrapper: FunctionComponent<{
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}>;
|
|
7
|
+
condition: boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Conditionally wrapps children with a component. If conditions are not met children mounted without the wrapper.
|
|
11
|
+
*/
|
|
12
|
+
export declare const ConditionalWrapper: FunctionComponent<Props>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Conditionally wrapps children with a component. If conditions are not met children mounted without the wrapper.
|
|
4
|
+
*/
|
|
5
|
+
export var ConditionalWrapper = function (_a) {
|
|
6
|
+
var condition = _a.condition, children = _a.children, Wrapper = _a.wrapper;
|
|
7
|
+
return condition ? React.createElement(Wrapper, null, children) : React.createElement(React.Fragment, null, children);
|
|
8
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { ErrorInfo, ReactNode } from "react";
|
|
2
|
+
interface Props {
|
|
3
|
+
boundaryName?: string;
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
interface State {
|
|
7
|
+
hasError: boolean;
|
|
8
|
+
error?: Error;
|
|
9
|
+
errorInfo?: ErrorInfo;
|
|
10
|
+
}
|
|
11
|
+
export declare class ErrorBoundary extends React.Component<Props, State> {
|
|
12
|
+
constructor(props: any);
|
|
13
|
+
static getDerivedStateFromError(error: any): {
|
|
14
|
+
hasError: boolean;
|
|
15
|
+
};
|
|
16
|
+
componentDidCatch(error: any, errorInfo: any): void;
|
|
17
|
+
render(): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __assign = (this && this.__assign) || function () {
|
|
17
|
+
__assign = Object.assign || function(t) {
|
|
18
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
+
s = arguments[i];
|
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
+
t[p] = s[p];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
};
|
|
25
|
+
return __assign.apply(this, arguments);
|
|
26
|
+
};
|
|
27
|
+
import { isDevelopment } from "@biblioteksentralen/utils";
|
|
28
|
+
import { Box } from "@chakra-ui/react";
|
|
29
|
+
import React from "react";
|
|
30
|
+
import { Alert } from "./Alert";
|
|
31
|
+
var StyledPre = function (props) { return (React.createElement(Box, __assign({ as: "pre", paddingTop: "0.5rem", wordBreak: "break-all", whiteSpace: "pre-wrap", fontSize: "0.8rem" }, props))); };
|
|
32
|
+
var ErrorBoundary = /** @class */ (function (_super) {
|
|
33
|
+
__extends(ErrorBoundary, _super);
|
|
34
|
+
function ErrorBoundary(props) {
|
|
35
|
+
var _this = _super.call(this, props) || this;
|
|
36
|
+
_this.state = { hasError: false };
|
|
37
|
+
return _this;
|
|
38
|
+
}
|
|
39
|
+
ErrorBoundary.getDerivedStateFromError = function (error) {
|
|
40
|
+
return { hasError: true };
|
|
41
|
+
};
|
|
42
|
+
ErrorBoundary.prototype.componentDidCatch = function (error, errorInfo) {
|
|
43
|
+
this.setState({ hasError: true, error: error, errorInfo: errorInfo });
|
|
44
|
+
console.error(error, { errorInfo: errorInfo, boundaryName: this.props.boundaryName });
|
|
45
|
+
};
|
|
46
|
+
ErrorBoundary.prototype.render = function () {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
if (this.state.hasError) {
|
|
49
|
+
var stackTrace = (_a = this.state.errorInfo) === null || _a === void 0 ? void 0 : _a.componentStack;
|
|
50
|
+
var errormsg = (_b = this.state.error) === null || _b === void 0 ? void 0 : _b.message;
|
|
51
|
+
var info = this.props.boundaryName;
|
|
52
|
+
return (React.createElement("div", null,
|
|
53
|
+
React.createElement(Alert, { status: "error" },
|
|
54
|
+
React.createElement("p", null, "Beklager, det skjedde en teknisk feil."),
|
|
55
|
+
isDevelopment() && (stackTrace || errormsg) && (React.createElement("div", null,
|
|
56
|
+
React.createElement(StyledPre, null, errormsg || ""),
|
|
57
|
+
React.createElement(StyledPre, null, info || ""),
|
|
58
|
+
React.createElement(StyledPre, null, stackTrace || ""))))));
|
|
59
|
+
}
|
|
60
|
+
return this.props.children;
|
|
61
|
+
};
|
|
62
|
+
return ErrorBoundary;
|
|
63
|
+
}(React.Component));
|
|
64
|
+
export { ErrorBoundary };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface Props {
|
|
3
|
+
id: string;
|
|
4
|
+
/**
|
|
5
|
+
* angir hvor mye luft til vil ha over HashLinkTarget ved bruk av hash-lenke, eks '4rem'
|
|
6
|
+
*/
|
|
7
|
+
spaceAbove?: string;
|
|
8
|
+
/**
|
|
9
|
+
* angir om du vil ha fokusramme rundt komponenten som mounter HashLinkTarget. Da må komponenten du wrapper med ha position: relative | absolute el
|
|
10
|
+
*/
|
|
11
|
+
focusOnParent?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function HashLinkTarget(props: Props): React.JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Box } from "@chakra-ui/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
var focusOnRelativeParentStyle = {
|
|
4
|
+
"&:focus-within": {
|
|
5
|
+
position: "static",
|
|
6
|
+
boxShadow: "none",
|
|
7
|
+
"&::after": {
|
|
8
|
+
content: '""',
|
|
9
|
+
position: "absolute",
|
|
10
|
+
top: 0,
|
|
11
|
+
left: 0,
|
|
12
|
+
height: "100%",
|
|
13
|
+
width: "100%",
|
|
14
|
+
pointerEvents: "none",
|
|
15
|
+
borderRadius: "0.25rem",
|
|
16
|
+
boxShadow: "var(--chakra-shadows-outline)",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
/*
|
|
21
|
+
* Komponent som sørger for luft over anchors (elementer man kan lenke til med hash-lenker feks <a href="#min-overskrift">Ta meg til overskrift</a>)
|
|
22
|
+
*/
|
|
23
|
+
export function HashLinkTarget(props) {
|
|
24
|
+
return (React.createElement(Box, { position: "relative", sx: props.focusOnParent ? focusOnRelativeParentStyle : undefined },
|
|
25
|
+
React.createElement(Box, { id: props.id, tabIndex: props.focusOnParent ? -1 : undefined, position: "absolute", top: "-".concat(props.spaceAbove || "2.5rem"), _focus: {
|
|
26
|
+
boxShadow: "none !important",
|
|
27
|
+
} })));
|
|
28
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BoxProps, ThemeTypings } from "@chakra-ui/react";
|
|
2
|
+
import { FunctionComponent, ReactNode } from "react";
|
|
3
|
+
type Props = {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
above?: ThemeTypings["breakpoints"];
|
|
6
|
+
below?: ThemeTypings["breakpoints"];
|
|
7
|
+
} & Omit<BoxProps, "display">;
|
|
8
|
+
/** Chakras <Hide /> component uses client side javascript to hide components. Causes components to flash on mobile while loading */
|
|
9
|
+
export declare const HideWithCSS: FunctionComponent<Props>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import { Box } from "@chakra-ui/react";
|
|
24
|
+
import React from "react";
|
|
25
|
+
/** Chakras <Hide /> component uses client side javascript to hide components. Causes components to flash on mobile while loading */
|
|
26
|
+
export var HideWithCSS = function (_a) {
|
|
27
|
+
var _b, _c;
|
|
28
|
+
var children = _a.children, above = _a.above, below = _a.below, chakraProps = __rest(_a, ["children", "above", "below"]);
|
|
29
|
+
var display = __assign(__assign({}, (!!below ? (_b = { base: "none" }, _b[below] = "block", _b) : {})), (!!above ? (_c = {}, _c[above] = "none", _c) : {}));
|
|
30
|
+
return (React.createElement(Box, __assign({}, chakraProps, { display: display }), children));
|
|
31
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FormLabelProps, InputProps } from "@chakra-ui/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
interface Props extends InputProps {
|
|
4
|
+
label: string;
|
|
5
|
+
hideLabel?: boolean;
|
|
6
|
+
labelProps?: FormLabelProps;
|
|
7
|
+
helperText?: string;
|
|
8
|
+
errorMessage?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creating custom input-component to make sure label is always set (for accessibility)
|
|
12
|
+
* Also handles some common needs (helper text and error message. For more advanced input-components we leave it to the consumers to compose custom input-components based on Chakra
|
|
13
|
+
*/
|
|
14
|
+
export declare const Input: React.ForwardRefExoticComponent<Props & React.RefAttributes<unknown>>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import { FormControl, FormErrorMessage, FormHelperText, FormLabel, Input as ChakraInput, } from "@chakra-ui/react";
|
|
24
|
+
import React, { forwardRef } from "react";
|
|
25
|
+
import { VisuallyHidden } from "./VisuallyHidden";
|
|
26
|
+
/**
|
|
27
|
+
* Creating custom input-component to make sure label is always set (for accessibility)
|
|
28
|
+
* Also handles some common needs (helper text and error message. For more advanced input-components we leave it to the consumers to compose custom input-components based on Chakra
|
|
29
|
+
*/
|
|
30
|
+
export var Input = forwardRef(function (props, ref) {
|
|
31
|
+
var labelProps = props.labelProps, label = props.label, helperText = props.helperText, errorMessage = props.errorMessage, hideLabel = props.hideLabel, inputProps = __rest(props, ["labelProps", "label", "helperText", "errorMessage", "hideLabel"]);
|
|
32
|
+
return (React.createElement(FormControl, { isInvalid: !!errorMessage },
|
|
33
|
+
React.createElement(FormLabel, __assign({ marginBottom: ".25em" }, labelProps), hideLabel ? React.createElement(VisuallyHidden, null, label) : label),
|
|
34
|
+
React.createElement(ChakraInput, __assign({ ref: ref }, inputProps)),
|
|
35
|
+
errorMessage && React.createElement(FormErrorMessage, null, errorMessage),
|
|
36
|
+
helperText && React.createElement(FormHelperText, null, helperText)));
|
|
37
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Modify } from "@biblioteksentralen/types";
|
|
2
|
+
import { ComponentWithAs, LinkProps } from "@chakra-ui/react";
|
|
3
|
+
import { CustomLinkVariants } from "../styles/chakraTheme/LinkStyles";
|
|
4
|
+
/**
|
|
5
|
+
* Re-exporting chackras Link with a customised types
|
|
6
|
+
* This causes both chakras native variants and our home-made variants to show up in auto-complete
|
|
7
|
+
*/
|
|
8
|
+
type LinkVariants = LinkProps["variant"] | CustomLinkVariants;
|
|
9
|
+
export declare const Link: ComponentWithAs<"a", Modify<LinkProps, {
|
|
10
|
+
variant?: LinkVariants;
|
|
11
|
+
}>>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import React, { useEffect } from "react";
|
|
13
|
+
import { VisuallyHidden as ChakraVisuallyHidden } from "@chakra-ui/react";
|
|
14
|
+
import { isDevelopment } from "@biblioteksentralen/utils";
|
|
15
|
+
// https://www.joshwcomeau.com/snippets/react-components/visually-hidden/
|
|
16
|
+
export function VisuallyHidden(_a) {
|
|
17
|
+
var children = _a.children, rest = __rest(_a, ["children"]);
|
|
18
|
+
var _b = React.useState(false), forceShow = _b[0], setForceShow = _b[1];
|
|
19
|
+
useEffect(function () {
|
|
20
|
+
if (isDevelopment()) {
|
|
21
|
+
var handleKeyDown_1 = function (ev) {
|
|
22
|
+
if (ev.key === "Alt") {
|
|
23
|
+
setForceShow(true);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var handleKeyUp_1 = function (ev) {
|
|
27
|
+
if (ev.key === "Alt") {
|
|
28
|
+
setForceShow(false);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
window.addEventListener("keydown", handleKeyDown_1);
|
|
32
|
+
window.addEventListener("keyup", handleKeyUp_1);
|
|
33
|
+
return function () {
|
|
34
|
+
window.removeEventListener("keydown", handleKeyDown_1);
|
|
35
|
+
window.removeEventListener("keyup", handleKeyUp_1);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}, []);
|
|
39
|
+
// position="fixed" løser bug der visually hidden ikke hindret tekst fra å ta plass i bredden
|
|
40
|
+
return forceShow ? React.createElement("span", null, children) : React.createElement(ChakraVisuallyHidden, { position: "fixed" }, children);
|
|
41
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import React from "react";
|
|
13
|
+
import { ErrorBoundary } from "./ErrorBoundary";
|
|
14
|
+
export var withErrorBoundary = function (Component, boundaryName) {
|
|
15
|
+
return React.forwardRef(function (props, ref) { return (React.createElement(ErrorBoundary, { boundaryName: boundaryName },
|
|
16
|
+
React.createElement(Component, __assign({}, props, { ref: ref })))); });
|
|
17
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "@chakra-ui/react";
|
|
2
|
+
export { Alert } from "./components/Alert";
|
|
3
|
+
export { Button } from "./components/Button";
|
|
4
|
+
export { ConditionalWrapper } from "./components/ConditionalWrapper";
|
|
5
|
+
export { HideWithCSS } from "./components/HideWithCSS";
|
|
6
|
+
export { Input } from "./components/Input";
|
|
7
|
+
export { Link } from "./components/Link";
|
|
8
|
+
export { VisuallyHidden } from "./components/VisuallyHidden";
|
|
9
|
+
export { ErrorBoundary } from "./components/ErrorBoundary";
|
|
10
|
+
export { HashLinkTarget } from "./components/HashLinkTarget";
|
|
11
|
+
export { withErrorBoundary } from "./components/withErrorBoundary";
|
|
12
|
+
export { biblioteksentralenChakraTheme } from "./styles/chakraTheme/biblioteksentralenChakraTheme";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "@chakra-ui/react"; // Exports Chakra components first to override some components later
|
|
2
|
+
export { Alert } from "./components/Alert"; // Overrides Chakras Alert
|
|
3
|
+
export { Button } from "./components/Button"; // Overrides Chakras Button
|
|
4
|
+
export { ConditionalWrapper } from "./components/ConditionalWrapper"; // Overrides Chakras Input
|
|
5
|
+
export { HideWithCSS } from "./components/HideWithCSS"; // Overrides Chakras HideWithCSS
|
|
6
|
+
export { Input } from "./components/Input"; // Overrides Chakras Input
|
|
7
|
+
export { Link } from "./components/Link"; // Overrides Chakras Link
|
|
8
|
+
export { VisuallyHidden } from "./components/VisuallyHidden"; // Overrides Chakras VisuallyHidden
|
|
9
|
+
export { ErrorBoundary } from "./components/ErrorBoundary";
|
|
10
|
+
export { HashLinkTarget } from "./components/HashLinkTarget";
|
|
11
|
+
export { withErrorBoundary } from "./components/withErrorBoundary";
|
|
12
|
+
export { biblioteksentralenChakraTheme } from "./styles/chakraTheme/biblioteksentralenChakraTheme";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { colors } from "@biblioteksentralen/utils";
|
|
2
|
+
var variants = {
|
|
3
|
+
primary: {
|
|
4
|
+
backgroundColor: colors.black,
|
|
5
|
+
color: "white",
|
|
6
|
+
_hover: {
|
|
7
|
+
backgroundColor: "hsla(0deg, 0%, 70%, 1)",
|
|
8
|
+
color: "black",
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
secondary: {
|
|
12
|
+
borderColor: "currentColor",
|
|
13
|
+
backgroundColor: "transparent",
|
|
14
|
+
color: "currentColor",
|
|
15
|
+
_hover: {
|
|
16
|
+
backgroundColor: "hsla(0deg, 0%, 50%, 0.15)",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
tertiary: {
|
|
20
|
+
backgroundColor: "transparent",
|
|
21
|
+
color: "currentColor",
|
|
22
|
+
_hover: {
|
|
23
|
+
backgroundColor: "hsla(0deg, 0%, 50%, 0.15)",
|
|
24
|
+
color: "currentColor",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
export var ButtonStyles = {
|
|
29
|
+
baseStyle: {
|
|
30
|
+
border: "transparent 0.1em solid",
|
|
31
|
+
borderRadius: "0.35em",
|
|
32
|
+
fontWeight: 600,
|
|
33
|
+
_disabled: {
|
|
34
|
+
backgroundColor: "".concat(colors.grey45, " !important"),
|
|
35
|
+
color: "white !important",
|
|
36
|
+
opacity: 1,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
sizes: {
|
|
40
|
+
sm: {
|
|
41
|
+
padding: "0.2em 0.5em",
|
|
42
|
+
fontSize: "1rem",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
variants: variants,
|
|
46
|
+
defaultProps: {
|
|
47
|
+
variant: "primary",
|
|
48
|
+
},
|
|
49
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { createMultiStyleConfigHelpers } from "@chakra-ui/react";
|
|
2
|
+
declare const defineMultiStyleConfig: ReturnType<typeof createMultiStyleConfigHelpers>["defineMultiStyleConfig"];
|
|
3
|
+
export declare const CheckboxStyles: ReturnType<typeof defineMultiStyleConfig>;
|
|
4
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createMultiStyleConfigHelpers } from "@chakra-ui/react";
|
|
2
|
+
import { checkboxAnatomy } from "@chakra-ui/anatomy";
|
|
3
|
+
var _a = createMultiStyleConfigHelpers(checkboxAnatomy.keys), definePartsStyle = _a.definePartsStyle, defineMultiStyleConfigWithTypeIssue = _a.defineMultiStyleConfig;
|
|
4
|
+
// https://github.com/pnpm/pnpm/issues/6089#issuecomment-1433207437
|
|
5
|
+
var defineMultiStyleConfig = defineMultiStyleConfigWithTypeIssue;
|
|
6
|
+
var baseStyle = definePartsStyle({
|
|
7
|
+
control: {
|
|
8
|
+
background: "white",
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
// https://github.com/pnpm/pnpm/issues/6089#issuecomment-1433207437
|
|
12
|
+
export var CheckboxStyles = defineMultiStyleConfig({ baseStyle: baseStyle });
|