@biblioteksentralen/react 1.0.0-beta.5 → 1.0.0-beta.7

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 (75) hide show
  1. package/README.md +11 -0
  2. package/dist/index.d.ts +118 -14
  3. package/dist/index.js +999 -43
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +558 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +22 -8
  8. package/.turbo/turbo-build.log +0 -8
  9. package/.turbo/turbo-test.log +0 -13
  10. package/.turbo/turbo-type-check.log +0 -4
  11. package/dist/BiblioteksentralenProvider.d.ts +0 -8
  12. package/dist/BiblioteksentralenProvider.js +0 -15
  13. package/dist/components/Alert.d.ts +0 -11
  14. package/dist/components/Alert.js +0 -59
  15. package/dist/components/Button.d.ts +0 -12
  16. package/dist/components/Button.js +0 -5
  17. package/dist/components/ConditionalWrapper.d.ts +0 -13
  18. package/dist/components/ConditionalWrapper.js +0 -15
  19. package/dist/components/ErrorBoundary.d.ts +0 -19
  20. package/dist/components/ErrorBoundary.js +0 -70
  21. package/dist/components/HashLinkTarget.d.ts +0 -14
  22. package/dist/components/HashLinkTarget.js +0 -35
  23. package/dist/components/HideWithCSS.d.ts +0 -10
  24. package/dist/components/HideWithCSS.js +0 -38
  25. package/dist/components/Input.d.ts +0 -15
  26. package/dist/components/Input.js +0 -63
  27. package/dist/components/Link.d.ts +0 -12
  28. package/dist/components/Link.js +0 -5
  29. package/dist/components/VisuallyHidden.d.ts +0 -6
  30. package/dist/components/VisuallyHidden.js +0 -68
  31. package/dist/components/withErrorBoundary.d.ts +0 -2
  32. package/dist/components/withErrorBoundary.js +0 -24
  33. package/dist/styles/chakraTheme/ButtonStyles.d.ts +0 -3
  34. package/dist/styles/chakraTheme/ButtonStyles.js +0 -52
  35. package/dist/styles/chakraTheme/CheckboxStyles.d.ts +0 -4
  36. package/dist/styles/chakraTheme/CheckboxStyles.js +0 -15
  37. package/dist/styles/chakraTheme/ContainerStyles.d.ts +0 -2
  38. package/dist/styles/chakraTheme/ContainerStyles.js +0 -8
  39. package/dist/styles/chakraTheme/HeadingStyles.d.ts +0 -2
  40. package/dist/styles/chakraTheme/HeadingStyles.js +0 -8
  41. package/dist/styles/chakraTheme/InputStyles.d.ts +0 -2
  42. package/dist/styles/chakraTheme/InputStyles.js +0 -42
  43. package/dist/styles/chakraTheme/LinkStyles.d.ts +0 -3
  44. package/dist/styles/chakraTheme/LinkStyles.js +0 -20
  45. package/dist/styles/chakraTheme/ModalStyles.d.ts +0 -2
  46. package/dist/styles/chakraTheme/ModalStyles.js +0 -13
  47. package/dist/styles/chakraTheme/SpinnerStyles.d.ts +0 -2
  48. package/dist/styles/chakraTheme/SpinnerStyles.js +0 -18
  49. package/dist/styles/chakraTheme/biblioteksentralenChakraTheme.d.ts +0 -2
  50. package/dist/styles/chakraTheme/biblioteksentralenChakraTheme.js +0 -35
  51. package/dist/styles/chakraTheme/sizes.d.ts +0 -8
  52. package/dist/styles/chakraTheme/sizes.js +0 -12
  53. package/src/BiblioteksentralenProvider.tsx +0 -16
  54. package/src/components/Alert.tsx +0 -60
  55. package/src/components/Button.tsx +0 -11
  56. package/src/components/ConditionalWrapper.tsx +0 -13
  57. package/src/components/ErrorBoundary.tsx +0 -60
  58. package/src/components/HashLinkTarget.tsx +0 -51
  59. package/src/components/HideWithCSS.tsx +0 -22
  60. package/src/components/Input.tsx +0 -37
  61. package/src/components/Link.tsx +0 -10
  62. package/src/components/VisuallyHidden.tsx +0 -36
  63. package/src/components/withErrorBoundary.tsx +0 -10
  64. package/src/index.ts +0 -16
  65. package/src/styles/chakraTheme/ButtonStyles.ts +0 -55
  66. package/src/styles/chakraTheme/CheckboxStyles.ts +0 -19
  67. package/src/styles/chakraTheme/ContainerStyles.ts +0 -7
  68. package/src/styles/chakraTheme/HeadingStyles.ts +0 -7
  69. package/src/styles/chakraTheme/InputStyles.ts +0 -41
  70. package/src/styles/chakraTheme/LinkStyles.ts +0 -23
  71. package/src/styles/chakraTheme/ModalStyles.ts +0 -12
  72. package/src/styles/chakraTheme/SpinnerStyles.ts +0 -13
  73. package/src/styles/chakraTheme/biblioteksentralenChakraTheme.ts +0 -34
  74. package/src/styles/chakraTheme/sizes.ts +0 -10
  75. package/tsconfig.json +0 -8
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ButtonStyles = void 0;
4
- var utils_1 = require("@biblioteksentralen/utils");
5
- var variants = {
6
- primary: {
7
- backgroundColor: utils_1.colors.black,
8
- color: "white",
9
- _hover: {
10
- backgroundColor: "hsla(0deg, 0%, 70%, 1)",
11
- color: "black",
12
- },
13
- },
14
- secondary: {
15
- borderColor: "currentColor",
16
- backgroundColor: "transparent",
17
- color: "currentColor",
18
- _hover: {
19
- backgroundColor: "hsla(0deg, 0%, 50%, 0.15)",
20
- },
21
- },
22
- tertiary: {
23
- backgroundColor: "transparent",
24
- color: "currentColor",
25
- _hover: {
26
- backgroundColor: "hsla(0deg, 0%, 50%, 0.15)",
27
- color: "currentColor",
28
- },
29
- },
30
- };
31
- exports.ButtonStyles = {
32
- baseStyle: {
33
- border: "transparent 0.1em solid",
34
- borderRadius: "0.35em",
35
- fontWeight: 600,
36
- _disabled: {
37
- backgroundColor: "".concat(utils_1.colors.grey45, " !important"),
38
- color: "white !important",
39
- opacity: 1,
40
- },
41
- },
42
- sizes: {
43
- sm: {
44
- padding: "0.2em 0.5em",
45
- fontSize: "1rem",
46
- },
47
- },
48
- variants: variants,
49
- defaultProps: {
50
- variant: "primary",
51
- },
52
- };
@@ -1,4 +0,0 @@
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 {};
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CheckboxStyles = void 0;
4
- var react_1 = require("@chakra-ui/react");
5
- var anatomy_1 = require("@chakra-ui/anatomy");
6
- var _a = (0, react_1.createMultiStyleConfigHelpers)(anatomy_1.checkboxAnatomy.keys), definePartsStyle = _a.definePartsStyle, defineMultiStyleConfigWithTypeIssue = _a.defineMultiStyleConfig;
7
- // https://github.com/pnpm/pnpm/issues/6089#issuecomment-1433207437
8
- var defineMultiStyleConfig = defineMultiStyleConfigWithTypeIssue;
9
- var baseStyle = definePartsStyle({
10
- control: {
11
- background: "white",
12
- },
13
- });
14
- // https://github.com/pnpm/pnpm/issues/6089#issuecomment-1433207437
15
- exports.CheckboxStyles = defineMultiStyleConfig({ baseStyle: baseStyle });
@@ -1,2 +0,0 @@
1
- import { ComponentStyleConfig } from "@chakra-ui/theme";
2
- export declare const ContainerStyles: ComponentStyleConfig;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContainerStyles = void 0;
4
- exports.ContainerStyles = {
5
- baseStyle: {
6
- px: ".75rem", // Padding left/right
7
- },
8
- };
@@ -1,2 +0,0 @@
1
- import { ComponentStyleConfig } from "@chakra-ui/theme";
2
- export declare const HeadingStyles: ComponentStyleConfig;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HeadingStyles = void 0;
4
- exports.HeadingStyles = {
5
- baseStyle: {
6
- fontWeight: "600",
7
- },
8
- };
@@ -1,2 +0,0 @@
1
- import { ComponentStyleConfig } from "@chakra-ui/theme";
2
- export declare const InputStyles: ComponentStyleConfig;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InputStyles = void 0;
4
- var theme_tools_1 = require("@chakra-ui/theme-tools");
5
- exports.InputStyles = {
6
- baseStyle: function (props) { return ({
7
- field: {
8
- _placeholder: {
9
- color: (0, theme_tools_1.mode)("gray.500", "whiteAlpha.500")(props),
10
- },
11
- },
12
- }); },
13
- variants: {
14
- filled: function (props) { return ({
15
- field: {
16
- bg: (0, theme_tools_1.mode)("gray.200", "whiteAlpha.100")(props),
17
- _hover: {
18
- bg: (0, theme_tools_1.mode)("gray.300", "whiteAlpha.200")(props),
19
- },
20
- },
21
- }); },
22
- outline: function (props) { return ({
23
- field: {
24
- borderColor: (0, theme_tools_1.mode)("gray.300", "whiteAlpha.300")(props),
25
- _hover: {
26
- borderColor: (0, theme_tools_1.mode)("gray.400", "whiteAlpha.400")(props),
27
- },
28
- },
29
- }); },
30
- flushed: function (props) { return ({
31
- field: {
32
- borderColor: (0, theme_tools_1.mode)("gray.300", "whiteAlpha.300")(props),
33
- _hover: {
34
- borderColor: (0, theme_tools_1.mode)("gray.400", "whiteAlpha.400")(props),
35
- },
36
- },
37
- }); },
38
- },
39
- defaultProps: {
40
- variant: "filled",
41
- },
42
- };
@@ -1,3 +0,0 @@
1
- import { ComponentStyleConfig } from "@chakra-ui/theme";
2
- export type CustomLinkVariants = "plain";
3
- export declare const LinkStyles: ComponentStyleConfig;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LinkStyles = void 0;
4
- var variants = {
5
- plain: {
6
- textDecoration: "none",
7
- _hover: {
8
- textDecoration: "underline",
9
- },
10
- },
11
- };
12
- exports.LinkStyles = {
13
- baseStyle: {
14
- textDecoration: "underline",
15
- _hover: {
16
- textDecoration: "none",
17
- },
18
- },
19
- variants: variants,
20
- };
@@ -1,2 +0,0 @@
1
- import { ComponentStyleConfig } from "@chakra-ui/theme";
2
- export declare const ModalStyles: ComponentStyleConfig;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModalStyles = void 0;
4
- exports.ModalStyles = {
5
- baseStyle: {
6
- // Fix for modal height on Safari iOS:
7
- // https://github.com/chakra-ui/chakra-ui/issues/4680#issuecomment-1301640929
8
- dialogContainer: {
9
- "@supports(height: -webkit-fill-available)": {},
10
- height: "100%",
11
- },
12
- },
13
- };
@@ -1,2 +0,0 @@
1
- import { ComponentStyleConfig } from "@chakra-ui/theme";
2
- export declare const SpinnerStyles: ComponentStyleConfig;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.SpinnerStyles = void 0;
15
- var utils_1 = require("@biblioteksentralen/utils");
16
- var react_1 = require("@chakra-ui/react");
17
- exports.SpinnerStyles = {};
18
- react_1.Spinner.defaultProps = __assign(__assign({}, react_1.Spinner.defaultProps), { speed: ".8s", color: utils_1.colors.accentBlueMedium, emptyColor: "rgba(0,0,0,.2)", thickness: ".175em" });
@@ -1,2 +0,0 @@
1
- import { ChakraTheme } from "@chakra-ui/theme";
2
- export declare const biblioteksentralenChakraTheme: Partial<ChakraTheme>;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.biblioteksentralenChakraTheme = void 0;
4
- var ButtonStyles_1 = require("./ButtonStyles");
5
- var CheckboxStyles_1 = require("./CheckboxStyles");
6
- var ContainerStyles_1 = require("./ContainerStyles");
7
- var HeadingStyles_1 = require("./HeadingStyles");
8
- var InputStyles_1 = require("./InputStyles");
9
- var LinkStyles_1 = require("./LinkStyles");
10
- var ModalStyles_1 = require("./ModalStyles");
11
- var SpinnerStyles_1 = require("./SpinnerStyles");
12
- var sizes_1 = require("./sizes");
13
- exports.biblioteksentralenChakraTheme = {
14
- styles: {
15
- global: {
16
- html: {
17
- fontSize: { base: "112.5%", md: "120%" },
18
- // Sørger for smooth scrolling for interne lenker som scroller til annet sted på siden,
19
- // men ikke hvis fokus er utenfor viduet, feks ved søk i tekst (ctrl + f)
20
- "&:focus-within": { scrollBehavior: "smooth !important" },
21
- },
22
- },
23
- },
24
- components: {
25
- Heading: HeadingStyles_1.HeadingStyles,
26
- Spinner: SpinnerStyles_1.SpinnerStyles,
27
- Link: LinkStyles_1.LinkStyles,
28
- Button: ButtonStyles_1.ButtonStyles,
29
- Input: InputStyles_1.InputStyles,
30
- Container: ContainerStyles_1.ContainerStyles,
31
- Modal: ModalStyles_1.ModalStyles,
32
- Checkbox: CheckboxStyles_1.CheckboxStyles,
33
- },
34
- sizes: sizes_1.sizes,
35
- };
@@ -1,8 +0,0 @@
1
- export declare const sizes: {
2
- container: {
3
- sm: string;
4
- md: string;
5
- lg: string;
6
- xl: string;
7
- };
8
- };
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sizes = void 0;
4
- var container = {
5
- sm: "40rem",
6
- md: "48rem",
7
- lg: "56rem", // Forsøker 56rem som standardbredde etter testing med Katrine
8
- xl: "80rem",
9
- };
10
- exports.sizes = {
11
- container: container,
12
- };
@@ -1,16 +0,0 @@
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
- );
@@ -1,60 +0,0 @@
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
- }
@@ -1,11 +0,0 @@
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 }>>;
@@ -1,13 +0,0 @@
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}</>;
@@ -1,60 +0,0 @@
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
- }
@@ -1,51 +0,0 @@
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
- }
@@ -1,22 +0,0 @@
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
- };
@@ -1,37 +0,0 @@
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
- });
@@ -1,10 +0,0 @@
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 }>>;
@@ -1,36 +0,0 @@
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
- }
@@ -1,10 +0,0 @@
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 DELETED
@@ -1,16 +0,0 @@
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 { BiblioteksentralenProvider } from "./BiblioteksentralenProvider";
11
- export { ErrorBoundary } from "./components/ErrorBoundary";
12
- export { HashLinkTarget } from "./components/HashLinkTarget";
13
- export { withErrorBoundary } from "./components/withErrorBoundary";
14
-
15
- export { colors } from "@biblioteksentralen/utils"; // Re-export colors for convenience
16
- export { biblioteksentralenChakraTheme } from "./styles/chakraTheme/biblioteksentralenChakraTheme";