@datalayer/primer-addons 0.2.1 → 0.2.3

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/README.md CHANGED
@@ -15,13 +15,13 @@ This project has been [shared in a discussion](https://github.com/primer/react/d
15
15
  ## Current Addons
16
16
 
17
17
  - [ ] Backdrop
18
- - [ ] BrandHeader
19
- - [ ] BrandHeaderLines
20
- - [ ] BrandFooter
18
+ - [ ] Brand Header
19
+ - [ ] Brand Header Lines
20
+ - [ ] Brand Footer
21
+ - [x] Content Loader
21
22
  - [x] Card
22
- - [x] ClosableFlash
23
- - [ ] MasonryBox
24
- - [ ] Skeleton
23
+ - [x] Closable Flash
24
+ - [ ] Masonry Box
25
25
  - [x] Slider
26
26
  - [x] Toolbar
27
27
 
@@ -1,6 +1,5 @@
1
1
  import React from "react";
2
2
  import { BoxProps } from "@primer/react";
3
- import { Icon } from "@primer/octicons-react";
4
3
  export type CardProps = Omit<BoxProps, 'border'> & {
5
4
  rounded?: 'small' | 'medium' | 'large' | 'full' | number;
6
5
  border?: boolean;
@@ -9,7 +8,7 @@ export type CardProps = Omit<BoxProps, 'border'> & {
9
8
  export type CardHeaderProps = {
10
9
  title?: string;
11
10
  description?: string;
12
- leadingIcon?: Icon;
11
+ leadingIcon?: React.ElementType;
13
12
  action?: React.ReactNode;
14
13
  };
15
14
  export type CardImageProps = {
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Box, StyledOcticon, Text } from "@primer/react";
2
+ import { Box, Octicon, Text } from "@primer/react";
3
3
  const roundedVals = {
4
4
  small: "3px",
5
5
  medium: "6px",
@@ -35,7 +35,7 @@ export const Card = (props) => {
35
35
  };
36
36
  Card.Header = (props) => {
37
37
  const { title, description, leadingIcon, action } = props;
38
- return _jsxs(Box, { display: "flex", alignItems: "center", sx: { p: 3 }, children: [leadingIcon && _jsx(Box, { sx: { mr: 3 }, children: _jsx(StyledOcticon, { size: "medium", icon: leadingIcon }) }), _jsxs(Box, { sx: { flexGrow: 1 }, children: [_jsx(Text, { display: "block", children: title }), _jsx(Text, { display: "block", color: "fg.muted", children: description })] }), action && _jsx(Box, { children: action })] });
38
+ return _jsxs(Box, { display: "flex", alignItems: "center", sx: { p: 3 }, children: [leadingIcon && _jsx(Box, { sx: { mr: 3 }, children: _jsx(Octicon, { size: "medium", icon: leadingIcon }) }), _jsxs(Box, { sx: { flexGrow: 1 }, children: [_jsx(Text, { display: "block", children: title }), _jsx(Text, { display: "block", color: "fg.muted", children: description })] }), action && _jsx(Box, { children: action })] });
39
39
  };
40
40
  Card.Image = ({ url, image, svg, height }) => {
41
41
  return (_jsxs(Box, { display: "block", width: "100%", height: `${height}px`, backgroundImage: `url(${url})`, sx: {
@@ -1,8 +1,7 @@
1
1
  import { FC } from "react";
2
2
  import { FlashProps } from "@primer/react";
3
- import { Icon } from "@primer/octicons-react";
4
3
  export type CloseableFlashProps = FlashProps & {
5
- leadingIcon?: Icon;
4
+ leadingIcon?: React.ElementType;
6
5
  onClose?: () => void;
7
6
  };
8
7
  export declare const CloseableFlash: FC<CloseableFlashProps>;
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from "react";
3
- import { Box, Flash, StyledOcticon, Text } from "@primer/react";
3
+ import { Box, Flash, Octicon, Text } from "@primer/react";
4
4
  import { XIcon } from "@primer/octicons-react";
5
5
  export const CloseableFlash = (props) => {
6
6
  const { leadingIcon, variant, onClose, ...otherProps } = props;
@@ -14,5 +14,5 @@ export const CloseableFlash = (props) => {
14
14
  if (!isVisible) {
15
15
  return null;
16
16
  }
17
- return (_jsx(Flash, { variant: variant, ...otherProps, children: _jsxs(Box, { display: "flex", justifyContent: "space-between", alignItems: "center", children: [_jsxs(Box, { sx: { flexGrow: 1 }, children: [leadingIcon && _jsx(StyledOcticon, { icon: leadingIcon }), _jsx(Text, { color: `${variant === "default" ? "accent" : (variant === "warning" ? "attention" : variant)}.fg`, children: props.children })] }), _jsx(Box, { onClick: handleClose, sx: { cursor: "pointer" }, children: _jsx(XIcon, { size: 20 }) })] }) }));
17
+ return (_jsx(Flash, { variant: variant, ...otherProps, children: _jsxs(Box, { display: "flex", justifyContent: "space-between", alignItems: "center", children: [_jsxs(Box, { sx: { flexGrow: 1 }, children: [leadingIcon && _jsx(Octicon, { icon: leadingIcon }), _jsx(Text, { color: `${variant === "default" ? "accent" : (variant === "warning" ? "attention" : variant)}.fg`, children: props.children })] }), _jsx(Box, { onClick: handleClose, sx: { cursor: "pointer" }, children: _jsx(XIcon, { size: 20 }) })] }) }));
18
18
  };
@@ -0,0 +1,6 @@
1
+ import 'react-loading-skeleton/dist/skeleton.css';
2
+ export interface ContentLoaderProps {
3
+ count?: number;
4
+ }
5
+ export declare const ContentLoader: (props: ContentLoaderProps) => import("react/jsx-runtime").JSX.Element;
6
+ export default ContentLoader;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Box } from "@primer/react";
3
+ import Skeleton, { SkeletonTheme } from "react-loading-skeleton";
4
+ import 'react-loading-skeleton/dist/skeleton.css';
5
+ export const ContentLoader = (props) => {
6
+ return (_jsx(Box, { children: _jsx(SkeletonTheme, { children: _jsx(Skeleton, { ...props }) }) }));
7
+ };
8
+ export default ContentLoader;
@@ -0,0 +1,14 @@
1
+ import type { StoryObj } from '@storybook/react';
2
+ import { ContentLoaderProps } from '../../../index';
3
+ declare const meta: {
4
+ title: string;
5
+ component: (props: ContentLoaderProps) => import("react/jsx-runtime").JSX.Element;
6
+ tags: string[];
7
+ parameters: {
8
+ layout: string;
9
+ };
10
+ };
11
+ export default meta;
12
+ type Story = StoryObj<typeof meta>;
13
+ export declare const ContentLoaderDay: Story;
14
+ export declare const ContentLoaderNight: Story;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ThemeProvider, BaseStyles, Box } from "@primer/react";
3
+ import { ContentLoader } from '../../../index';
4
+ const meta = {
5
+ title: 'Components/ContentLoader',
6
+ component: ContentLoader,
7
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs
8
+ tags: ['autodocs'],
9
+ parameters: {
10
+ // More on how to position stories at: https://storybook.js.org/docs/react/configure/story-layout
11
+ layout: 'fullscreen',
12
+ },
13
+ };
14
+ export default meta;
15
+ const ThemedContentLoader = (props) => _jsx(ThemeProvider, { colorMode: props.colorMode, children: _jsx(BaseStyles, { children: _jsx(Box, { p: 3, bg: "canvas.default", children: _jsx(ContentLoader, { ...props }) }) }) });
16
+ export const ContentLoaderDay = {
17
+ args: {
18
+ count: 3
19
+ },
20
+ render: (args) => _jsx(ThemedContentLoader, { ...args, colorMode: "day" })
21
+ };
22
+ export const ContentLoaderNight = {
23
+ args: {
24
+ count: 3
25
+ },
26
+ render: (args) => _jsx(ThemedContentLoader, { ...args, colorMode: "night" })
27
+ };
@@ -0,0 +1,6 @@
1
+ export type CircleIconProps = {
2
+ color?: string;
3
+ variant?: 'fg' | 'default' | 'muted' | 'onEmphasis' | 'subtle';
4
+ };
5
+ export declare const CircleIcon: ({ color, variant, }: CircleIconProps) => import("react/jsx-runtime").JSX.Element;
6
+ export default CircleIcon;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useTheme } from '@primer/react';
3
+ import { CircleCurrentColorIcon } from '@datalayer/icons-react';
4
+ const COLORS = {
5
+ 'danger': 'danger',
6
+ };
7
+ export const CircleIcon = ({ color = 'white', variant = 'fg', }) => {
8
+ const { theme } = useTheme();
9
+ return (_jsx(CircleCurrentColorIcon, { fill: theme?.colors[COLORS[color]][variant] ?? color ?? 'white' }));
10
+ };
11
+ export default CircleIcon;
@@ -0,0 +1,14 @@
1
+ import type { StoryObj } from '@storybook/react';
2
+ import { CircleIconProps } from '../../../index';
3
+ declare const meta: {
4
+ title: string;
5
+ component: ({ color, variant, }: CircleIconProps) => import("react/jsx-runtime").JSX.Element;
6
+ tags: string[];
7
+ parameters: {
8
+ layout: string;
9
+ };
10
+ };
11
+ export default meta;
12
+ type Story = StoryObj<typeof meta>;
13
+ export declare const CircleIconDay: Story;
14
+ export declare const CircleIconNight: Story;
@@ -0,0 +1,29 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ThemeProvider, BaseStyles, Box } from "@primer/react";
3
+ import { CircleIcon } from '../../../index';
4
+ const meta = {
5
+ title: 'Components/CircleIcon',
6
+ component: CircleIcon,
7
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs
8
+ tags: ['autodocs'],
9
+ parameters: {
10
+ // More on how to position stories at: https://storybook.js.org/docs/react/configure/story-layout
11
+ layout: 'fullscreen',
12
+ },
13
+ };
14
+ export default meta;
15
+ const ThemedCircleIcon = (props) => _jsx(ThemeProvider, { colorMode: props.colorMode, children: _jsx(BaseStyles, { children: _jsx(Box, { p: 3, bg: "canvas.default", children: _jsx(CircleIcon, { ...props }) }) }) });
16
+ export const CircleIconDay = {
17
+ args: {
18
+ color: 'danger',
19
+ variant: 'fg',
20
+ },
21
+ render: (args) => _jsx(ThemedCircleIcon, { ...args, colorMode: "day" })
22
+ };
23
+ export const CircleIconNight = {
24
+ args: {
25
+ color: 'danger',
26
+ variant: 'fg',
27
+ },
28
+ render: (args) => _jsx(ThemedCircleIcon, { ...args, colorMode: "night" })
29
+ };
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ export interface OverlayProps {
3
+ direction: 'left' | 'right';
4
+ isOpen?: boolean;
5
+ setIsOpen?: React.Dispatch<React.SetStateAction<boolean>>;
6
+ content: JSX.Element;
7
+ buttonRef?: React.RefObject<HTMLButtonElement>;
8
+ confirmButtonRef?: React.RefObject<HTMLButtonElement>;
9
+ headingRef?: React.RefObject<HTMLHeadingElement>;
10
+ }
11
+ export declare const Overlay: (props: OverlayProps) => import("react/jsx-runtime").JSX.Element;
12
+ export default Overlay;
@@ -0,0 +1,49 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useState } from 'react';
3
+ import { Button, Overlay as PrimerOverlay, Box } from "@primer/react";
4
+ const PrimerAddonOverlay = (props) => {
5
+ const { content, buttonRef, confirmButtonRef, headingRef, isOpen, setIsOpen } = props;
6
+ const [direction, _] = useState(props.direction);
7
+ const [top, setTop] = useState(0);
8
+ useEffect(() => {
9
+ setTop(headingRef?.current?.getBoundingClientRect().bottom ?? 0);
10
+ }, [headingRef]);
11
+ const closeOverlay = () => setIsOpen(false);
12
+ return (confirmButtonRef && buttonRef ?
13
+ _jsx(_Fragment, { children: isOpen ?
14
+ direction === 'left' ?
15
+ _jsx(PrimerOverlay, { initialFocusRef: confirmButtonRef, returnFocusRef: buttonRef, ignoreClickRefs: [buttonRef], onEscape: closeOverlay, onClickOutside: closeOverlay, width: "auto", anchorSide: "inside-right", top: top, children: _jsxs(Box, { sx: {
16
+ /* We need to remove the padding */
17
+ height: `calc(100vh - ${top}px - 8px)`,
18
+ width: '500px',
19
+ display: 'flex',
20
+ flexDirection: 'column',
21
+ alignItems: 'center',
22
+ padding: '4px'
23
+ }, children: [_jsx(Box, { sx: {
24
+ display: 'flex',
25
+ justifyContent: 'right',
26
+ width: '100%'
27
+ }, children: _jsx(Button, { ref: confirmButtonRef, onClick: closeOverlay, children: "Close me" }) }), content] }) })
28
+ :
29
+ _jsx(PrimerOverlay, { initialFocusRef: confirmButtonRef, returnFocusRef: buttonRef, ignoreClickRefs: [buttonRef], onEscape: closeOverlay, onClickOutside: closeOverlay, width: "auto", anchorSide: 'inside-left', right: 0, position: "fixed", top: top, children: _jsxs(Box, { sx: {
30
+ /* We need to remove the padding */
31
+ height: `calc(100vh - ${top}px - 8px)`,
32
+ width: '500px',
33
+ display: 'flex',
34
+ flexDirection: 'column',
35
+ alignItems: 'center',
36
+ padding: '4px'
37
+ }, children: [_jsx(Box, { sx: {
38
+ display: 'flex',
39
+ justifyContent: 'right',
40
+ width: '100%'
41
+ }, children: _jsx(Button, { ref: confirmButtonRef, onClick: closeOverlay, children: "Close me" }) }), content] }) })
42
+ : _jsx(_Fragment, {}) })
43
+ :
44
+ _jsx(_Fragment, {}));
45
+ };
46
+ export const Overlay = (props) => {
47
+ return (_jsx(PrimerAddonOverlay, { ...props }));
48
+ };
49
+ export default Overlay;
@@ -0,0 +1,16 @@
1
+ import type { StoryObj } from '@storybook/react';
2
+ import { OverlayProps } from './../Overlay';
3
+ declare const meta: {
4
+ title: string;
5
+ component: (props: OverlayProps) => import("react/jsx-runtime").JSX.Element;
6
+ tags: string[];
7
+ parameters: {
8
+ layout: string;
9
+ };
10
+ };
11
+ export default meta;
12
+ type Story = StoryObj<typeof meta>;
13
+ export declare const OverlayDayLeft: Story;
14
+ export declare const OverlayDayRight: Story;
15
+ export declare const OverlayNightLeft: Story;
16
+ export declare const OverlayNightRight: Story;
@@ -0,0 +1,52 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useRef } from "react";
3
+ import { Heading, Text, ThemeProvider, BaseStyles, Box, Button, } from "@primer/react";
4
+ import { Overlay } from './../Overlay';
5
+ const meta = {
6
+ title: 'Components/Overlay',
7
+ component: Overlay,
8
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs
9
+ tags: ['autodocs'],
10
+ parameters: {
11
+ // More on how to position stories at: https://storybook.js.org/docs/react/configure/story-layout
12
+ layout: 'fullscreen',
13
+ },
14
+ };
15
+ export default meta;
16
+ const ThemedOverlay = (props) => {
17
+ const [isOpen, setIsOpen] = useState(false);
18
+ const buttonRef = useRef(null);
19
+ const confirmButtonRef = useRef(null);
20
+ const headingRef = useRef(null);
21
+ return (_jsx(ThemeProvider, { colorMode: props.colorMode, children: _jsx(BaseStyles, { children: _jsx(Box, { p: 3, bg: "canvas.default", children: _jsxs(Box, { children: [_jsx(Box, { sx: { width: '100%', bg: 'darkgray' }, children: _jsx(Heading, { ref: headingRef, children: "Header" }) }), _jsxs(Box, { children: [_jsx(Button, { ref: buttonRef, onClick: () => {
22
+ setIsOpen(!isOpen);
23
+ }, children: "Open overlay" }), _jsx(Overlay, { ...props, isOpen: isOpen, setIsOpen: setIsOpen, buttonRef: buttonRef, confirmButtonRef: confirmButtonRef, headingRef: props.direction === 'left' ? headingRef : undefined })] })] }) }) }) }));
24
+ };
25
+ export const OverlayDayLeft = {
26
+ args: {
27
+ direction: "left",
28
+ content: _jsx(Text, { children: "\uD83D\uDC48 Look, left aligned, no heading." }),
29
+ },
30
+ render: (args) => _jsx(ThemedOverlay, { ...args, colorMode: "day" })
31
+ };
32
+ export const OverlayDayRight = {
33
+ args: {
34
+ direction: "right",
35
+ content: _jsx(Text, { children: "Look, right aligned, on heading \uD83D\uDC49" }),
36
+ },
37
+ render: (args) => _jsx(ThemedOverlay, { ...args, colorMode: "day" })
38
+ };
39
+ export const OverlayNightLeft = {
40
+ args: {
41
+ direction: "left",
42
+ content: _jsx(Text, { children: "\uD83D\uDC48 Look, left aligned, no heading." }),
43
+ },
44
+ render: (args) => _jsx(ThemedOverlay, { ...args, colorMode: "night" })
45
+ };
46
+ export const OverlayNightRight = {
47
+ args: {
48
+ direction: "right",
49
+ content: _jsx(Text, { children: "Look, right aligned, on heading \uD83D\uDC49" })
50
+ },
51
+ render: (args) => _jsx(ThemedOverlay, { ...args, colorMode: "night" })
52
+ };
package/lib/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  export * from "./components/card/Card";
2
+ export * from "./components/content-loader/ContentLoader";
2
3
  export * from "./components/closeable-flash/CloseableFlash";
4
+ export * from "./components/icons/CircleIcon";
5
+ export * from "./components/overlay/Overlay";
3
6
  export * from "./components/slider/Slider";
4
7
  export * from "./components/toolbar/Toolbar";
package/lib/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  export * from "./components/card/Card";
2
+ export * from "./components/content-loader/ContentLoader";
2
3
  export * from "./components/closeable-flash/CloseableFlash";
4
+ export * from "./components/icons/CircleIcon";
5
+ export * from "./components/overlay/Overlay";
3
6
  export * from "./components/slider/Slider";
4
7
  export * from "./components/toolbar/Toolbar";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalayer/primer-addons",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "license": "BSD-3-Clause",
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -23,13 +23,12 @@
23
23
  },
24
24
  "homepage": "https://primer-addons.datalayer.tech",
25
25
  "dependencies": {
26
- "@datalayer/icons-react": "0.2.1",
27
- "@primer/brand-primitives": "0.29.1",
26
+ "@datalayer/icons-react": "0.2.3",
28
27
  "@primer/octicons-react": "19.6.0",
29
- "@primer/react": "0.0.0-20230912151940",
30
- "@primer/react-brand": "0.29.1",
28
+ "@primer/react": "36.6.0",
31
29
  "react": "18.2.0",
32
30
  "react-dom": "18.2.0",
31
+ "react-loading-skeleton": "3.3.1",
33
32
  "styled-components": "5.3.10"
34
33
  },
35
34
  "devDependencies": {
@@ -44,7 +43,7 @@
44
43
  "@types/react-dom": "18.2.5",
45
44
  "@typescript-eslint/eslint-plugin": "^5.57.1",
46
45
  "@typescript-eslint/parser": "^5.57.1",
47
- "@vitejs/plugin-react": "^4.0.0",
46
+ "@vitejs/plugin-react": "4.2.1",
48
47
  "eslint": "^8.38.0",
49
48
  "eslint-plugin-react-hooks": "^4.6.0",
50
49
  "eslint-plugin-react-refresh": "^0.3.4",
@@ -53,5 +52,6 @@
53
52
  "storybook": "^7.0.9",
54
53
  "typescript": "^5.0.2",
55
54
  "vite": "^4.3.2"
56
- }
55
+ },
56
+ "packageManager": "yarn@3.5.0"
57
57
  }