@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.
Files changed (72) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.turbo/turbo-test.log +13 -0
  3. package/.turbo/turbo-type-check.log +4 -0
  4. package/LICENSE +21 -0
  5. package/dist/BiblioteksentralenProvider.d.ts +8 -0
  6. package/dist/BiblioteksentralenProvider.js +8 -0
  7. package/dist/components/Alert.d.ts +11 -0
  8. package/dist/components/Alert.js +52 -0
  9. package/dist/components/Button.d.ts +12 -0
  10. package/dist/components/Button.js +2 -0
  11. package/dist/components/ConditionalWrapper.d.ts +13 -0
  12. package/dist/components/ConditionalWrapper.js +8 -0
  13. package/dist/components/ErrorBoundary.d.ts +19 -0
  14. package/dist/components/ErrorBoundary.js +64 -0
  15. package/dist/components/HashLinkTarget.d.ts +14 -0
  16. package/dist/components/HashLinkTarget.js +28 -0
  17. package/dist/components/HideWithCSS.d.ts +10 -0
  18. package/dist/components/HideWithCSS.js +31 -0
  19. package/dist/components/Input.d.ts +15 -0
  20. package/dist/components/Input.js +37 -0
  21. package/dist/components/Link.d.ts +12 -0
  22. package/dist/components/Link.js +2 -0
  23. package/dist/components/VisuallyHidden.d.ts +6 -0
  24. package/dist/components/VisuallyHidden.js +41 -0
  25. package/dist/components/withErrorBoundary.d.ts +2 -0
  26. package/dist/components/withErrorBoundary.js +17 -0
  27. package/dist/index.d.ts +12 -0
  28. package/dist/index.js +12 -0
  29. package/dist/styles/chakraTheme/ButtonStyles.d.ts +3 -0
  30. package/dist/styles/chakraTheme/ButtonStyles.js +49 -0
  31. package/dist/styles/chakraTheme/CheckboxStyles.d.ts +4 -0
  32. package/dist/styles/chakraTheme/CheckboxStyles.js +12 -0
  33. package/dist/styles/chakraTheme/ContainerStyles.d.ts +2 -0
  34. package/dist/styles/chakraTheme/ContainerStyles.js +5 -0
  35. package/dist/styles/chakraTheme/HeadingStyles.d.ts +2 -0
  36. package/dist/styles/chakraTheme/HeadingStyles.js +5 -0
  37. package/dist/styles/chakraTheme/InputStyles.d.ts +2 -0
  38. package/dist/styles/chakraTheme/InputStyles.js +39 -0
  39. package/dist/styles/chakraTheme/LinkStyles.d.ts +3 -0
  40. package/dist/styles/chakraTheme/LinkStyles.js +17 -0
  41. package/dist/styles/chakraTheme/ModalStyles.d.ts +2 -0
  42. package/dist/styles/chakraTheme/ModalStyles.js +10 -0
  43. package/dist/styles/chakraTheme/SpinnerStyles.d.ts +2 -0
  44. package/dist/styles/chakraTheme/SpinnerStyles.js +15 -0
  45. package/dist/styles/chakraTheme/biblioteksentralenChakraTheme.d.ts +2 -0
  46. package/dist/styles/chakraTheme/biblioteksentralenChakraTheme.js +32 -0
  47. package/dist/styles/chakraTheme/sizes.d.ts +8 -0
  48. package/dist/styles/chakraTheme/sizes.js +9 -0
  49. package/package.json +42 -0
  50. package/src/BiblioteksentralenProvider.tsx +16 -0
  51. package/src/components/Alert.tsx +60 -0
  52. package/src/components/Button.tsx +11 -0
  53. package/src/components/ConditionalWrapper.tsx +13 -0
  54. package/src/components/ErrorBoundary.tsx +60 -0
  55. package/src/components/HashLinkTarget.tsx +51 -0
  56. package/src/components/HideWithCSS.tsx +22 -0
  57. package/src/components/Input.tsx +37 -0
  58. package/src/components/Link.tsx +10 -0
  59. package/src/components/VisuallyHidden.tsx +36 -0
  60. package/src/components/withErrorBoundary.tsx +10 -0
  61. package/src/index.ts +14 -0
  62. package/src/styles/chakraTheme/ButtonStyles.ts +55 -0
  63. package/src/styles/chakraTheme/CheckboxStyles.ts +19 -0
  64. package/src/styles/chakraTheme/ContainerStyles.ts +7 -0
  65. package/src/styles/chakraTheme/HeadingStyles.ts +7 -0
  66. package/src/styles/chakraTheme/InputStyles.ts +41 -0
  67. package/src/styles/chakraTheme/LinkStyles.ts +23 -0
  68. package/src/styles/chakraTheme/ModalStyles.ts +12 -0
  69. package/src/styles/chakraTheme/SpinnerStyles.ts +13 -0
  70. package/src/styles/chakraTheme/biblioteksentralenChakraTheme.ts +34 -0
  71. package/src/styles/chakraTheme/sizes.ts +10 -0
  72. package/tsconfig.json +9 -0
@@ -0,0 +1,39 @@
1
+ import { mode } from "@chakra-ui/theme-tools";
2
+ export var InputStyles = {
3
+ baseStyle: function (props) { return ({
4
+ field: {
5
+ _placeholder: {
6
+ color: mode("gray.500", "whiteAlpha.500")(props),
7
+ },
8
+ },
9
+ }); },
10
+ variants: {
11
+ filled: function (props) { return ({
12
+ field: {
13
+ bg: mode("gray.200", "whiteAlpha.100")(props),
14
+ _hover: {
15
+ bg: mode("gray.300", "whiteAlpha.200")(props),
16
+ },
17
+ },
18
+ }); },
19
+ outline: function (props) { return ({
20
+ field: {
21
+ borderColor: mode("gray.300", "whiteAlpha.300")(props),
22
+ _hover: {
23
+ borderColor: mode("gray.400", "whiteAlpha.400")(props),
24
+ },
25
+ },
26
+ }); },
27
+ flushed: function (props) { return ({
28
+ field: {
29
+ borderColor: mode("gray.300", "whiteAlpha.300")(props),
30
+ _hover: {
31
+ borderColor: mode("gray.400", "whiteAlpha.400")(props),
32
+ },
33
+ },
34
+ }); },
35
+ },
36
+ defaultProps: {
37
+ variant: "filled",
38
+ },
39
+ };
@@ -0,0 +1,3 @@
1
+ import { ComponentStyleConfig } from "@chakra-ui/theme";
2
+ export type CustomLinkVariants = "plain";
3
+ export declare const LinkStyles: ComponentStyleConfig;
@@ -0,0 +1,17 @@
1
+ var variants = {
2
+ plain: {
3
+ textDecoration: "none",
4
+ _hover: {
5
+ textDecoration: "underline",
6
+ },
7
+ },
8
+ };
9
+ export var LinkStyles = {
10
+ baseStyle: {
11
+ textDecoration: "underline",
12
+ _hover: {
13
+ textDecoration: "none",
14
+ },
15
+ },
16
+ variants: variants,
17
+ };
@@ -0,0 +1,2 @@
1
+ import { ComponentStyleConfig } from "@chakra-ui/theme";
2
+ export declare const ModalStyles: ComponentStyleConfig;
@@ -0,0 +1,10 @@
1
+ export var ModalStyles = {
2
+ baseStyle: {
3
+ // Fix for modal height on Safari iOS:
4
+ // https://github.com/chakra-ui/chakra-ui/issues/4680#issuecomment-1301640929
5
+ dialogContainer: {
6
+ "@supports(height: -webkit-fill-available)": {},
7
+ height: "100%",
8
+ },
9
+ },
10
+ };
@@ -0,0 +1,2 @@
1
+ import { ComponentStyleConfig } from "@chakra-ui/theme";
2
+ export declare const SpinnerStyles: ComponentStyleConfig;
@@ -0,0 +1,15 @@
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 { colors } from "@biblioteksentralen/utils";
13
+ import { Spinner } from "@chakra-ui/react";
14
+ export var SpinnerStyles = {};
15
+ Spinner.defaultProps = __assign(__assign({}, Spinner.defaultProps), { speed: ".8s", color: colors.accentBlueMedium, emptyColor: "rgba(0,0,0,.2)", thickness: ".175em" });
@@ -0,0 +1,2 @@
1
+ import { ChakraTheme } from "@chakra-ui/theme";
2
+ export declare const biblioteksentralenChakraTheme: Partial<ChakraTheme>;
@@ -0,0 +1,32 @@
1
+ import { ButtonStyles } from "./ButtonStyles";
2
+ import { CheckboxStyles } from "./CheckboxStyles";
3
+ import { ContainerStyles } from "./ContainerStyles";
4
+ import { HeadingStyles } from "./HeadingStyles";
5
+ import { InputStyles } from "./InputStyles";
6
+ import { LinkStyles } from "./LinkStyles";
7
+ import { ModalStyles } from "./ModalStyles";
8
+ import { SpinnerStyles } from "./SpinnerStyles";
9
+ import { sizes } from "./sizes";
10
+ export var biblioteksentralenChakraTheme = {
11
+ styles: {
12
+ global: {
13
+ html: {
14
+ fontSize: { base: "112.5%", md: "120%" },
15
+ // Sørger for smooth scrolling for interne lenker som scroller til annet sted på siden,
16
+ // men ikke hvis fokus er utenfor viduet, feks ved søk i tekst (ctrl + f)
17
+ "&:focus-within": { scrollBehavior: "smooth !important" },
18
+ },
19
+ },
20
+ },
21
+ components: {
22
+ Heading: HeadingStyles,
23
+ Spinner: SpinnerStyles,
24
+ Link: LinkStyles,
25
+ Button: ButtonStyles,
26
+ Input: InputStyles,
27
+ Container: ContainerStyles,
28
+ Modal: ModalStyles,
29
+ Checkbox: CheckboxStyles,
30
+ },
31
+ sizes: sizes,
32
+ };
@@ -0,0 +1,8 @@
1
+ export declare const sizes: {
2
+ container: {
3
+ sm: string;
4
+ md: string;
5
+ lg: string;
6
+ xl: string;
7
+ };
8
+ };
@@ -0,0 +1,9 @@
1
+ var container = {
2
+ sm: "40rem",
3
+ md: "48rem",
4
+ lg: "56rem", // Forsøker 56rem som standardbredde etter testing med Katrine
5
+ xl: "80rem",
6
+ };
7
+ export var sizes = {
8
+ container: container,
9
+ };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@biblioteksentralen/react",
3
+ "version": "1.0.0-beta.1",
4
+ "description": "React library for reusable code in Biblioteksentralens js-apps",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "keywords": [],
8
+ "author": "Biblioteksentralen",
9
+ "license": "MIT",
10
+ "private": false,
11
+ "prettier": {
12
+ "printWidth": 120
13
+ },
14
+ "lint-staged": {
15
+ "*.{js,css,md,ts,tsx}": "prettier --write"
16
+ },
17
+ "dependencies": {
18
+ "@chakra-ui/anatomy": "^2.2.2",
19
+ "@chakra-ui/react": "^2.8.2",
20
+ "@chakra-ui/theme": "^3.3.1",
21
+ "@chakra-ui/theme-tools": "^2.1.2",
22
+ "date-fns": "^3.0.6"
23
+ },
24
+ "devDependencies": {
25
+ "@types/react": "^18.2.45",
26
+ "react": "^18.2.0",
27
+ "react-dom": "^18.2.0",
28
+ "@biblioteksentralen/icons": "1.0.0-beta.4",
29
+ "@biblioteksentralen/utils": "1.0.0-beta.5",
30
+ "@biblioteksentralen/types": "1.0.0-beta.1"
31
+ },
32
+ "peerDependencies": {
33
+ "react": "^18.2.0",
34
+ "react-dom": "^18.2.0"
35
+ },
36
+ "scripts": {
37
+ "test": "vitest --watch=false",
38
+ "type-check": "tsc --noEmit",
39
+ "clean": "rm -rf node_modules",
40
+ "build": "rm -rf dist && tsc"
41
+ }
42
+ }
@@ -0,0 +1,16 @@
1
+ import { ChakraProvider, ChakraTheme, extendTheme } from "@chakra-ui/react";
2
+ import React, { ReactNode } from "react";
3
+ import { biblioteksentralenChakraTheme } from "./styles/chakraTheme/biblioteksentralenChakraTheme";
4
+
5
+ interface Props {
6
+ children: ReactNode;
7
+ customTheme?: Partial<ChakraTheme>;
8
+ }
9
+
10
+ const emptyTheme = {};
11
+
12
+ export const BiblioteksentralenProvider = (props: Props) => (
13
+ <ChakraProvider theme={extendTheme(biblioteksentralenChakraTheme, props.customTheme ?? emptyTheme)}>
14
+ {props.children}
15
+ </ChakraProvider>
16
+ );
@@ -0,0 +1,60 @@
1
+ import { BsCheckCircle, BsExclamationCircle, BsXCircle, InformationIcon } from "@biblioteksentralen/icons";
2
+ import { colors } from "@biblioteksentralen/utils";
3
+ import { AlertProps, Box, Flex, FlexProps } from "@chakra-ui/react";
4
+ import React, { ReactNode } from "react";
5
+
6
+ type Status = Exclude<AlertProps["status"], undefined | "loading">;
7
+ type Variants = "inline";
8
+
9
+ const colorLookup: Record<Status, { bg: string; color: string }> = {
10
+ info: { bg: colors.lightBlue, color: colors.accentBlueMedium },
11
+ warning: { bg: colors.alertYellow, color: colors.statusYellow },
12
+ success: { bg: "green.100", color: "green.600" },
13
+ error: { bg: colors.alertRed, color: colors.statusRed },
14
+ };
15
+
16
+ const iconLookup: Record<Status, React.ReactElement> = {
17
+ info: <InformationIcon role="img" aria-label="Informasjon" />,
18
+ warning: <BsExclamationCircle role="img" aria-label="Advarsel" />,
19
+ success: <BsCheckCircle role="img" aria-label="Suksess" />,
20
+ error: <BsXCircle role="img" aria-label="Feil" />,
21
+ };
22
+
23
+ interface Props extends FlexProps {
24
+ children: ReactNode;
25
+ status: Status;
26
+ variant?: Variants;
27
+ }
28
+
29
+ const variantStyles: Record<Variants, FlexProps> = {
30
+ inline: {
31
+ borderColor: "transparent",
32
+ backgroundColor: "transparent",
33
+ padding: "0",
34
+ },
35
+ };
36
+
37
+ export function Alert({ status, children, variant, ...rest }: Props) {
38
+ const colors = colorLookup[status];
39
+ return (
40
+ <Flex
41
+ role="alert"
42
+ flexWrap="wrap"
43
+ alignItems="center"
44
+ gridGap="0.5rem 1rem"
45
+ background="white"
46
+ border={`0.1rem solid`}
47
+ borderColor={colors.color}
48
+ backgroundColor={colors.bg}
49
+ padding="0.75rem"
50
+ borderRadius="0.3rem"
51
+ {...(variant ? variantStyles[variant] : {})}
52
+ {...rest}
53
+ >
54
+ <Box color={colors.color} flex="0 0" marginLeft="auto" marginRight="auto" lineHeight="1" fontSize="1.5em">
55
+ {iconLookup[status]}
56
+ </Box>
57
+ <Box flex="1">{children}</Box>
58
+ </Flex>
59
+ );
60
+ }
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ import { Button as ChakraButton, ButtonProps, ComponentWithAs } from "@chakra-ui/react";
3
+ import { Modify } from "@biblioteksentralen/types";
4
+ import { CustomButtonVariants } from "../styles/chakraTheme/ButtonStyles";
5
+
6
+ /**
7
+ * Re-exporting chackras Button with a customised types
8
+ * This causes both chakras native variants and our home-made variants to show up in auto-complete
9
+ */
10
+ type ButtonVariants = ButtonProps["variant"] | CustomButtonVariants;
11
+ export const Button = ChakraButton as ComponentWithAs<"button", Modify<ButtonProps, { variant?: ButtonVariants }>>;
@@ -0,0 +1,13 @@
1
+ import React, { FunctionComponent, ReactNode } from "react";
2
+
3
+ type Props = {
4
+ children: ReactNode;
5
+ wrapper: FunctionComponent<{ children: ReactNode }>;
6
+ condition: boolean;
7
+ };
8
+
9
+ /**
10
+ * Conditionally wrapps children with a component. If conditions are not met children mounted without the wrapper.
11
+ */
12
+ export const ConditionalWrapper: FunctionComponent<Props> = ({ condition, children, wrapper: Wrapper }) =>
13
+ condition ? <Wrapper>{children}</Wrapper> : <>{children}</>;
@@ -0,0 +1,60 @@
1
+ import { isDevelopment } from "@biblioteksentralen/utils";
2
+ import { Box, BoxProps } from "@chakra-ui/react";
3
+ import React, { ErrorInfo, ReactNode } from "react";
4
+ import { Alert } from "./Alert";
5
+
6
+ interface Props {
7
+ boundaryName?: string;
8
+ children: ReactNode;
9
+ }
10
+
11
+ interface State {
12
+ hasError: boolean;
13
+ error?: Error;
14
+ errorInfo?: ErrorInfo;
15
+ }
16
+
17
+ const StyledPre = (props: BoxProps) => (
18
+ <Box as="pre" paddingTop="0.5rem" wordBreak="break-all" whiteSpace="pre-wrap" fontSize="0.8rem" {...props} />
19
+ );
20
+
21
+ export class ErrorBoundary extends React.Component<Props, State> {
22
+ constructor(props: any) {
23
+ super(props);
24
+ this.state = { hasError: false };
25
+ }
26
+
27
+ static getDerivedStateFromError(error: any) {
28
+ return { hasError: true };
29
+ }
30
+
31
+ componentDidCatch(error: any, errorInfo: any) {
32
+ this.setState({ hasError: true, error, errorInfo });
33
+ console.error(error, { errorInfo, boundaryName: this.props.boundaryName });
34
+ }
35
+
36
+ render() {
37
+ if (this.state.hasError) {
38
+ const stackTrace = this.state.errorInfo?.componentStack;
39
+ const errormsg = this.state.error?.message;
40
+ const info = this.props.boundaryName;
41
+
42
+ return (
43
+ <div>
44
+ <Alert status="error">
45
+ <p>Beklager, det skjedde en teknisk feil.</p>
46
+ {isDevelopment() && (stackTrace || errormsg) && (
47
+ <div>
48
+ <StyledPre>{errormsg || ""}</StyledPre>
49
+ <StyledPre>{info || ""}</StyledPre>
50
+ <StyledPre>{stackTrace || ""}</StyledPre>
51
+ </div>
52
+ )}
53
+ </Alert>
54
+ </div>
55
+ );
56
+ }
57
+
58
+ return this.props.children;
59
+ }
60
+ }
@@ -0,0 +1,51 @@
1
+ import { Box } from "@chakra-ui/react";
2
+ import React from "react";
3
+
4
+ interface Props {
5
+ id: string;
6
+ /**
7
+ * angir hvor mye luft til vil ha over HashLinkTarget ved bruk av hash-lenke, eks '4rem'
8
+ */
9
+ spaceAbove?: string;
10
+ /**
11
+ * angir om du vil ha fokusramme rundt komponenten som mounter HashLinkTarget. Da må komponenten du wrapper med ha position: relative | absolute el
12
+ */
13
+ focusOnParent?: boolean;
14
+ }
15
+
16
+ const focusOnRelativeParentStyle = {
17
+ "&:focus-within": {
18
+ position: "static",
19
+ boxShadow: "none",
20
+ "&::after": {
21
+ content: '""',
22
+ position: "absolute",
23
+ top: 0,
24
+ left: 0,
25
+ height: "100%",
26
+ width: "100%",
27
+ pointerEvents: "none",
28
+ borderRadius: "0.25rem",
29
+ boxShadow: "var(--chakra-shadows-outline)",
30
+ },
31
+ },
32
+ };
33
+
34
+ /*
35
+ * 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>)
36
+ */
37
+ export function HashLinkTarget(props: Props) {
38
+ return (
39
+ <Box position="relative" sx={props.focusOnParent ? focusOnRelativeParentStyle : undefined}>
40
+ <Box
41
+ id={props.id}
42
+ tabIndex={props.focusOnParent ? -1 : undefined}
43
+ position="absolute"
44
+ top={`-${props.spaceAbove || "2.5rem"}`}
45
+ _focus={{
46
+ boxShadow: "none !important",
47
+ }}
48
+ />
49
+ </Box>
50
+ );
51
+ }
@@ -0,0 +1,22 @@
1
+ import { Box, BoxProps, ThemeTypings } from "@chakra-ui/react";
2
+ import React, { FunctionComponent, ReactNode } from "react";
3
+
4
+ type Props = {
5
+ children: ReactNode;
6
+ above?: ThemeTypings["breakpoints"];
7
+ below?: ThemeTypings["breakpoints"];
8
+ } & Omit<BoxProps, "display">;
9
+
10
+ /** Chakras <Hide /> component uses client side javascript to hide components. Causes components to flash on mobile while loading */
11
+ export const HideWithCSS: FunctionComponent<Props> = ({ children, above, below, ...chakraProps }) => {
12
+ const display: BoxProps["display"] = {
13
+ ...(!!below ? { base: "none", [below]: "block" } : {}),
14
+ ...(!!above ? { [above]: "none" } : {}),
15
+ };
16
+
17
+ return (
18
+ <Box {...chakraProps} display={display}>
19
+ {children}
20
+ </Box>
21
+ );
22
+ };
@@ -0,0 +1,37 @@
1
+ import {
2
+ FormControl,
3
+ FormErrorMessage,
4
+ FormHelperText,
5
+ FormLabel,
6
+ FormLabelProps,
7
+ Input as ChakraInput,
8
+ InputProps,
9
+ } from "@chakra-ui/react";
10
+ import React, { forwardRef } from "react";
11
+ import { VisuallyHidden } from "./VisuallyHidden";
12
+
13
+ interface Props extends InputProps {
14
+ label: string;
15
+ hideLabel?: boolean;
16
+ labelProps?: FormLabelProps;
17
+ helperText?: string;
18
+ errorMessage?: string;
19
+ }
20
+
21
+ /**
22
+ * Creating custom input-component to make sure label is always set (for accessibility)
23
+ * 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
24
+ */
25
+ export const Input = forwardRef((props: Props, ref) => {
26
+ const { labelProps, label, helperText, errorMessage, hideLabel, ...inputProps } = props;
27
+ return (
28
+ <FormControl isInvalid={!!errorMessage}>
29
+ <FormLabel marginBottom=".25em" {...labelProps}>
30
+ {hideLabel ? <VisuallyHidden>{label}</VisuallyHidden> : label}
31
+ </FormLabel>
32
+ <ChakraInput ref={ref} {...inputProps} />
33
+ {errorMessage && <FormErrorMessage>{errorMessage}</FormErrorMessage>}
34
+ {helperText && <FormHelperText>{helperText}</FormHelperText>}
35
+ </FormControl>
36
+ );
37
+ });
@@ -0,0 +1,10 @@
1
+ import { Modify } from "@biblioteksentralen/types";
2
+ import { Link as ChakraLink, ComponentWithAs, LinkProps } from "@chakra-ui/react";
3
+ import { CustomLinkVariants } from "../styles/chakraTheme/LinkStyles";
4
+
5
+ /**
6
+ * Re-exporting chackras Link with a customised types
7
+ * This causes both chakras native variants and our home-made variants to show up in auto-complete
8
+ */
9
+ type LinkVariants = LinkProps["variant"] | CustomLinkVariants;
10
+ export const Link = ChakraLink as ComponentWithAs<"a", Modify<LinkProps, { variant?: LinkVariants }>>;
@@ -0,0 +1,36 @@
1
+ import React, { HTMLAttributes, ReactNode, useEffect } from "react";
2
+ import { VisuallyHidden as ChakraVisuallyHidden } from "@chakra-ui/react";
3
+ import { isDevelopment } from "@biblioteksentralen/utils";
4
+
5
+ interface Props extends HTMLAttributes<HTMLSpanElement> {
6
+ children: ReactNode;
7
+ }
8
+
9
+ // https://www.joshwcomeau.com/snippets/react-components/visually-hidden/
10
+ export function VisuallyHidden({ children, ...rest }: Props) {
11
+ const [forceShow, setForceShow] = React.useState(false);
12
+
13
+ useEffect(() => {
14
+ if (isDevelopment()) {
15
+ const handleKeyDown = (ev: KeyboardEvent) => {
16
+ if (ev.key === "Alt") {
17
+ setForceShow(true);
18
+ }
19
+ };
20
+ const handleKeyUp = (ev: KeyboardEvent) => {
21
+ if (ev.key === "Alt") {
22
+ setForceShow(false);
23
+ }
24
+ };
25
+ window.addEventListener("keydown", handleKeyDown);
26
+ window.addEventListener("keyup", handleKeyUp);
27
+ return () => {
28
+ window.removeEventListener("keydown", handleKeyDown);
29
+ window.removeEventListener("keyup", handleKeyUp);
30
+ };
31
+ }
32
+ }, []);
33
+
34
+ // position="fixed" løser bug der visually hidden ikke hindret tekst fra å ta plass i bredden
35
+ return forceShow ? <span>{children}</span> : <ChakraVisuallyHidden position="fixed">{children}</ChakraVisuallyHidden>;
36
+ }
@@ -0,0 +1,10 @@
1
+ import React from "react";
2
+ import { ErrorBoundary } from "./ErrorBoundary";
3
+
4
+ export const withErrorBoundary = <Props,>(Component: React.ComponentType<Props>, boundaryName: string) => {
5
+ return React.forwardRef((props: Props, ref) => (
6
+ <ErrorBoundary boundaryName={boundaryName}>
7
+ <Component {...props} ref={ref} />
8
+ </ErrorBoundary>
9
+ ));
10
+ };
package/src/index.ts ADDED
@@ -0,0 +1,14 @@
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
+
10
+ export { ErrorBoundary } from "./components/ErrorBoundary";
11
+ export { HashLinkTarget } from "./components/HashLinkTarget";
12
+ export { withErrorBoundary } from "./components/withErrorBoundary";
13
+
14
+ export { biblioteksentralenChakraTheme } from "./styles/chakraTheme/biblioteksentralenChakraTheme";
@@ -0,0 +1,55 @@
1
+ import { colors } from "@biblioteksentralen/utils";
2
+ import { ComponentStyleConfig } from "@chakra-ui/theme";
3
+ import { SystemStyleInterpolation } from "@chakra-ui/theme-tools";
4
+
5
+ export type CustomButtonVariants = "primary" | "secondary" | "tertiary";
6
+
7
+ const variants: Record<CustomButtonVariants, SystemStyleInterpolation> = {
8
+ primary: {
9
+ backgroundColor: colors.black,
10
+ color: "white",
11
+ _hover: {
12
+ backgroundColor: "hsla(0deg, 0%, 70%, 1)",
13
+ color: "black",
14
+ },
15
+ },
16
+ secondary: {
17
+ borderColor: "currentColor",
18
+ backgroundColor: "transparent",
19
+ color: "currentColor",
20
+ _hover: {
21
+ backgroundColor: "hsla(0deg, 0%, 50%, 0.15)",
22
+ },
23
+ },
24
+ tertiary: {
25
+ backgroundColor: "transparent",
26
+ color: "currentColor",
27
+ _hover: {
28
+ backgroundColor: "hsla(0deg, 0%, 50%, 0.15)",
29
+ color: "currentColor",
30
+ },
31
+ },
32
+ };
33
+
34
+ export const ButtonStyles: ComponentStyleConfig = {
35
+ baseStyle: {
36
+ border: "transparent 0.1em solid",
37
+ borderRadius: "0.35em",
38
+ fontWeight: 600,
39
+ _disabled: {
40
+ backgroundColor: `${colors.grey45} !important`,
41
+ color: "white !important",
42
+ opacity: 1,
43
+ },
44
+ },
45
+ sizes: {
46
+ sm: {
47
+ padding: "0.2em 0.5em",
48
+ fontSize: "1rem",
49
+ },
50
+ },
51
+ variants: variants,
52
+ defaultProps: {
53
+ variant: "primary",
54
+ },
55
+ };
@@ -0,0 +1,19 @@
1
+ import { createMultiStyleConfigHelpers } from "@chakra-ui/react";
2
+ import { checkboxAnatomy } from "@chakra-ui/anatomy";
3
+
4
+ const { definePartsStyle, defineMultiStyleConfig: defineMultiStyleConfigWithTypeIssue } = createMultiStyleConfigHelpers(
5
+ checkboxAnatomy.keys
6
+ );
7
+
8
+ // https://github.com/pnpm/pnpm/issues/6089#issuecomment-1433207437
9
+ const defineMultiStyleConfig: ReturnType<typeof createMultiStyleConfigHelpers>["defineMultiStyleConfig"] =
10
+ defineMultiStyleConfigWithTypeIssue;
11
+
12
+ const baseStyle = definePartsStyle({
13
+ control: {
14
+ background: "white",
15
+ },
16
+ });
17
+
18
+ // https://github.com/pnpm/pnpm/issues/6089#issuecomment-1433207437
19
+ export const CheckboxStyles: ReturnType<typeof defineMultiStyleConfig> = defineMultiStyleConfig({ baseStyle });
@@ -0,0 +1,7 @@
1
+ import { ComponentStyleConfig } from "@chakra-ui/theme";
2
+
3
+ export const ContainerStyles: ComponentStyleConfig = {
4
+ baseStyle: {
5
+ px: ".75rem", // Padding left/right
6
+ },
7
+ };
@@ -0,0 +1,7 @@
1
+ import { ComponentStyleConfig } from "@chakra-ui/theme";
2
+
3
+ export const HeadingStyles: ComponentStyleConfig = {
4
+ baseStyle: {
5
+ fontWeight: "600",
6
+ },
7
+ };