Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@datalayer/primer-addons",
"version": "1.0.3",
"version": "1.0.4",
"license": "BSD-3-Clause",
"scripts": {
"dev": "vite",
Expand Down
7 changes: 7 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from "./box/Box";
export * from "./card/Card";
export * from "./content-loader/ContentLoader";
export * from "./closeable-flash/CloseableFlash";
export * from "./icons/CircleIcon";
export * from "./overlay/Overlay";
export * from "./slider/Slider";
9 changes: 2 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
export * from "./components/box/Box";
export * from "./components/card/Card";
export * from "./components/content-loader/ContentLoader";
export * from "./components/closeable-flash/CloseableFlash";
export * from "./components/icons/CircleIcon";
export * from "./components/overlay/Overlay";
export * from "./components/slider/Slider";
export * from "./components";
export * from "./utils";
70 changes: 70 additions & 0 deletions src/utils/Helper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2023-2025 Datalayer, Inc.
* Distributed under the terms of the Modified BSD License.
*/

import React, { Ref, PropsWithChildren } from 'react';
import { AnimateProps } from '@primer/react-brand';

/**
* Layout
*/
export const Container = ({
children,
style,
}: {
children: React.ReactElement[] | React.ReactElement;
style?: React.CSSProperties;
}) => (
<div style={{ maxWidth: 1024, margin: '0 auto', ...style }}>{children}</div>
);

type RedlineBackgroundProps = {
height?: number;
hasBorder?: boolean;
};

export function RedlineBackground({
height,
hasBorder = true,
...rest
}: PropsWithChildren<RedlineBackgroundProps>) {
return (
<div
style={{
display: 'flex',
overflow: 'hidden',
border: hasBorder
? '1px solid var(--base-color-scale-red-2)'
: undefined,
backgroundImage:
'linear-gradient(45deg, var(--base-color-scale-red-0) 12.5%, hsla(var(--base-color-scale-red-2-hsl) / 50%) 12.5%, hsla(var(--base-color-scale-red-2-hsl) / 50%) 50%, var(--base-color-scale-red-0) 50%, var(--base-color-scale-red-0) 62.5%, hsla(var(--base-color-scale-red-2-hsl) / 50%) 62.5%, hsla(var(--base-color-scale-red-2-hsl) / 50%) 100%)',
backgroundSize: '5.66px 5.66px',
WebkitBoxPack: 'center',
justifyContent: 'center',
alignItems: 'center',
width: '100%',
height,
}}
{...rest}
/>
);
}

/**
* Base Types
*
* Component helper type to be extended by component types, e.g.:
* type CustomComponentProps = BaseProps<HTMLDivElement> & { ... }
*
* Example use:
* const CustomComponent = forwardRef<HTMLDivElement, CustomComponentProps>(({className, ...props}, ref) => { ... })
* // OR:
* const CustomComponent = forwardRef(({className: CustomComponentProps, ...props}, ref: Ref<HTMLDivElement>) => { ... })
*/
export type BaseProps<T> = {
className?: string;
id?: string;
ref?: Ref<T>;
animate?: AnimateProps;
};
30 changes: 30 additions & 0 deletions src/utils/Portals.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2023-2025 Datalayer, Inc.
* Distributed under the terms of the Modified BSD License.
*/

import { registerPortalRoot } from '@primer/react';

import '@primer/react-brand/lib/css/main.css';

const PRIMER_PORTAL_ROOT_ID = '__primerPortalRoot__';

type Colormode = 'light' | 'dark' | 'auto';

/**
* Ensure we define a root for Primer portal root.
*
* @see https://github.com/primer/react/blob/main/packages/react/src/Portal/Portal.tsx#L23
* @see https://github.com/primer/react/blob/030fe020b48b7f12c2994c6614e5d4191fe764ee/src/Portal/Portal.tsx#L33
*/
export const setupPrimerPortals = (colormode: Colormode = 'light') => {
const body = document.body;
body.dataset['portalRoot'] = 'true';
body.dataset['colorMode'] = colormode;
body.dataset['lightTheme'] = 'light';
body.dataset['darkTheme'] = 'dark';
body.id = PRIMER_PORTAL_ROOT_ID;
registerPortalRoot(body);
};

export default setupPrimerPortals;
18 changes: 18 additions & 0 deletions src/utils/Styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2023-2025 Datalayer, Inc.
* Distributed under the terms of the Modified BSD License.
*/

import { ThemeProvider, BaseStyles } from '@primer/react';

export const Styles = () => {
return (
<>
<ThemeProvider>
<BaseStyles />
</ThemeProvider>
</>
);
};

export default Styles;
7 changes: 7 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright (c) 2023-2025 Datalayer, Inc.
* Distributed under the terms of the Modified BSD License.
*/

export * from './Helper';
export * from './Portals';
Loading