Skip to content

Commit a5cb740

Browse files
committed
chore: add Box
1 parent 08351be commit a5cb740

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@datalayer/primer-addons",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"license": "BSD-3-Clause",
55
"scripts": {
66
"dev": "vite",

src/components/box/Box.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2021-2024 Datalayer, Inc.
3+
*
4+
* Datalayer License
5+
*/
6+
7+
import { ComponentProps } from 'react';
8+
import styled from 'styled-components';
9+
import type { BackgroundProps, BorderProps, ColorProps, FlexboxProps, GridProps, LayoutProps, PositionProps, ShadowProps, SpaceProps, TypographyProps } from 'styled-system';
10+
import {background, border, color, flexbox, grid, layout, position, shadow, space, typography} from 'styled-system';
11+
import sx, {type SxProp } from './sx';
12+
13+
type StyledBoxProps = SxProp &
14+
SpaceProps &
15+
ColorProps &
16+
TypographyProps &
17+
LayoutProps &
18+
FlexboxProps &
19+
GridProps &
20+
BackgroundProps &
21+
BorderProps &
22+
PositionProps &
23+
ShadowProps;
24+
25+
export const Box = styled.div<StyledBoxProps>(
26+
space,
27+
color,
28+
typography,
29+
layout,
30+
flexbox,
31+
grid,
32+
background,
33+
border,
34+
position,
35+
shadow,
36+
sx,
37+
);
38+
39+
export type BoxProps = ComponentProps<typeof Box>;
40+
41+
export default Box;

src/components/box/sx.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2021-2024 Datalayer, Inc.
3+
*
4+
* Datalayer License
5+
*/
6+
7+
import type {SystemCssProperties, SystemStyleObject} from '@styled-system/css'
8+
import css from '@styled-system/css'
9+
// import type {ThemeColorPaths, ThemeShadowPaths} from '@primer/react/test-helpers'
10+
import type {ColorProps, BorderColorProps, ShadowProps} from 'styled-system'
11+
import merge from 'deepmerge'
12+
13+
type ThemeColorPaths = string
14+
type ThemeShadowPaths = string
15+
16+
export type BetterCssProperties = {
17+
[K in keyof SystemCssProperties]: K extends keyof ColorProps
18+
? ThemeColorPaths | SystemCssProperties[K]
19+
: K extends keyof BorderColorProps
20+
? ThemeColorPaths | SystemCssProperties[K]
21+
: K extends keyof ShadowProps
22+
? ThemeShadowPaths | SystemCssProperties[K]
23+
: SystemCssProperties[K]
24+
}
25+
26+
// Support CSS custom properties in the `sx` prop
27+
export type CSSCustomProperties = {
28+
[key: `--${string}`]: string | number
29+
}
30+
31+
type CSSSelectorObject = {
32+
[cssSelector: string]: SystemStyleObject | CSSCustomProperties
33+
}
34+
35+
export type BetterSystemStyleObject = BetterCssProperties | SystemStyleObject | CSSCustomProperties | CSSSelectorObject
36+
37+
export interface SxProp {
38+
sx?: BetterSystemStyleObject
39+
}
40+
41+
const sx = (props: SxProp) => css(props.sx)
42+
43+
export default sx
44+
45+
export {merge}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from "./components/box/Box";
12
export * from "./components/card/Card";
23
export * from "./components/content-loader/ContentLoader";
34
export * from "./components/closeable-flash/CloseableFlash";

0 commit comments

Comments
 (0)