@awesomephant/reactcake 1.1.0 → 1.1.2

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.
@@ -1,22 +1,27 @@
1
1
  import { type ReactNode } from "react";
2
2
  import { useReactCake } from "../ReactCake";
3
+ import { LayoutProps } from "../types";
3
4
 
4
- interface HtmlProps {
5
+ interface HtmlProps extends LayoutProps {
5
6
  children?: ReactNode;
6
7
  }
7
8
 
8
- const Html = ({ children }: HtmlProps) => {
9
+ const Html = ({ overflow = "visible", label, labelledBy, describedBy, children }: HtmlProps) => {
9
10
  const { padding } = useReactCake();
10
11
 
11
12
  return (
12
13
  <div
13
14
  className="reactcake-html"
15
+ aria-label={labelledBy}
16
+ aria-describedby={describedBy}
17
+ role={label ? "figure" : "none"}
14
18
  style={{
15
19
  position: "absolute",
16
- top: padding.top,
17
- left: padding.left,
18
- right: padding.right,
19
- bottom: padding.bottom,
20
+ top: `${padding.top}px`,
21
+ left: `${padding.left}px`,
22
+ right: `${padding.right}px`,
23
+ bottom: `${padding.bottom}px`,
24
+ overflow,
20
25
  }}
21
26
  >
22
27
  {children}
@@ -1,18 +1,29 @@
1
1
  import { type ReactNode } from "react";
2
2
  import { useReactCake } from "../ReactCake";
3
+ import { LayoutProps } from "../types";
3
4
 
4
- interface SvgProps {
5
- overflow?: "visible" | "hidden";
5
+ interface SvgProps extends LayoutProps {
6
+ title?: string;
6
7
  children?: ReactNode;
7
8
  }
8
9
 
9
- const ScaledSvg = ({ children, overflow = "visible" }: SvgProps) => {
10
+ const ScaledSvg = ({
11
+ children,
12
+ label,
13
+ labelledBy,
14
+ describedBy,
15
+ title,
16
+ overflow = "visible",
17
+ }: SvgProps) => {
10
18
  const { padding } = useReactCake();
11
19
  return (
12
20
  <>
13
21
  <style>{`svg * { vector-effect: non-scaling-stroke;}`}</style>
14
22
  <svg
15
23
  className="reactcake-svg"
24
+ aria-label={labelledBy}
25
+ aria-describedby={describedBy}
26
+ role={label ? "figure" : "none"}
16
27
  preserveAspectRatio="none"
17
28
  height={`calc(100% - ${padding.top}px - ${padding.bottom}px`}
18
29
  width={`calc(100% - ${padding.left}px - ${padding.right}px`}
@@ -24,6 +35,7 @@ const ScaledSvg = ({ children, overflow = "visible" }: SvgProps) => {
24
35
  overflow: overflow,
25
36
  }}
26
37
  >
38
+ {title && <title>{title}</title>}
27
39
  {children}
28
40
  </svg>
29
41
  </>
package/lib/Svg/index.tsx CHANGED
@@ -1,12 +1,13 @@
1
1
  import { type ReactNode } from "react";
2
2
  import { useReactCake } from "../ReactCake";
3
+ import { LayoutProps } from "../types";
3
4
 
4
- interface SvgProps {
5
- overflow?: "visible" | "hidden";
5
+ interface SvgProps extends LayoutProps {
6
+ title?: string;
6
7
  children?: ReactNode;
7
8
  }
8
9
 
9
- const Svg = ({ children, overflow = "hidden" }: SvgProps) => {
10
+ const Svg = ({ children, title, overflow = "hidden" }: SvgProps) => {
10
11
  const { padding } = useReactCake();
11
12
  return (
12
13
  <svg
@@ -24,6 +25,7 @@ const Svg = ({ children, overflow = "hidden" }: SvgProps) => {
24
25
  overflow: overflow,
25
26
  }}
26
27
  >
28
+ {title && <title>{title}</title>}
27
29
  <g transform={`translate(${padding.left} ${padding.top})`}>{children}</g>
28
30
  </svg>
29
31
  );
package/lib/types.ts CHANGED
@@ -37,3 +37,10 @@ export interface ContextValue {
37
37
  zGet?: (d: unknown) => number | string;
38
38
  padding: Padding;
39
39
  }
40
+
41
+ export interface LayoutProps {
42
+ overflow?: "hidden" | "visible",
43
+ label?: string;
44
+ labelledBy?: string;
45
+ describedBy?: string;
46
+ }
package/notes.md CHANGED
@@ -1 +1,11 @@
1
1
  - Anything you draw past the edges shows up in the padding, the way it does on the other layouts. (https://layercake.graphics/guide#canvas)
2
+
3
+ from: https://layercake.graphics/guide
4
+
5
+ - it reverses the default range from [0, height] to [height, 0] in order to match the DOM coordinate system and make drawing easier out of the box.
6
+ - The default ranges for each dimension are:
7
+
8
+ x: [0, width]
9
+ y: [height, 0], unless using a scaleBand or scalePoint and it is [0, height]
10
+ r: [1, 25]. The min is 1 and not zero because this is a scaleSqrt by default and 0 is not allowed in that type of chart.
11
+ z: [0, width]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesomephant/reactcake",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "A headless chart framework for React inspired by Layercake",
5
5
  "keywords": [
6
6
  "react",
@@ -1,5 +1,6 @@
1
1
  // @ts-check
2
2
  import { defineConfig } from 'astro/config';
3
+ import {transformerRenderIndentGuides, transformerRenderLineNumber} from "@shikijs/transformers"
3
4
 
4
5
  import mdx from '@astrojs/mdx';
5
6
 
@@ -7,9 +8,14 @@ import react from '@astrojs/react';
7
8
 
8
9
  export default defineConfig({
9
10
  markdown: {
10
- shikiConfig: {
11
- theme: 'github-light-high-contrast',
12
- }
11
+ shikiConfig: {
12
+ theme: 'css-variables',
13
+ defaultColor: false,
14
+ transformers:[transformerRenderLineNumber(), transformerRenderIndentGuides()]
15
+ },
16
+ syntaxHighlight: {
17
+ type: 'shiki',
18
+ },
13
19
  },
14
20
 
15
21
  integrations: [mdx(), react()]
package/site/package.json CHANGED
@@ -21,6 +21,7 @@
21
21
  "react-dom": "^19.3.1"
22
22
  },
23
23
  "devDependencies": {
24
+ "@shikijs/transformers": "^4.6.0",
24
25
  "@types/d3-scale": "^4.0.9",
25
26
  "@types/react": "^19.3.0",
26
27
  "@types/react-dom": "^19.3.0"
@@ -12,5 +12,6 @@ const {height, width = "100%"} = Astro.props
12
12
  .container {
13
13
  margin: 1rem 0;
14
14
  border: 1px solid var(--blue-50);
15
+ font-family: sans-serif;
15
16
  }
16
17
  </style>
@@ -62,7 +62,7 @@ const AxisX = ({
62
62
  height: `${tickLength}px`,
63
63
  }}
64
64
  >
65
- <span className={styles.tick_mark}></span>
65
+ <span style={{ height: `${tickLength}px` }} className={styles.tick__mark}></span>
66
66
  <span
67
67
  className={styles.tick__text}
68
68
  style={{
@@ -6,7 +6,12 @@
6
6
 
7
7
  .tick {
8
8
  position: absolute;
9
+ }
10
+
11
+ .tick__mark {
9
12
  border-left: 1px solid var(--blue-50);
13
+ position: absolute;
14
+ transform: translateX(-50%);
10
15
  }
11
16
 
12
17
  .gridline {
@@ -1,9 +1,10 @@
1
1
  import { ReactCake, ScaledSvg, Html } from "../../../lib";
2
- import AxisX from "./AxisX/index";
2
+ import AxisX from "./AxisX/AxisX";
3
3
  import AxisY from "./AxisY";
4
4
  import Columns from "./Columns";
5
5
  import { scaleLinear, scaleBand } from "d3-scale";
6
6
  import { max } from "d3-array";
7
+ import DebugPadding from "./DebugPadding";
7
8
 
8
9
  const data = [
9
10
  { year: 2021, value: 18 },
@@ -29,7 +30,8 @@ export default function ColumnChart() {
29
30
  yDomain={[0, max(data, (d) => d[yKey]) + 5]}
30
31
  padding={{ top: 10, left: 35, right: 10, bottom: 30 }}
31
32
  >
32
- <Html>
33
+ <Html overflow="visible">
34
+ <DebugPadding />
33
35
  <AxisX grid ticks />
34
36
  <AxisY grid ticks={3} />
35
37
  </Html>
@@ -0,0 +1,17 @@
1
+ import { useReactCake } from "../../../lib";
2
+
3
+ export default function DebugPadding() {
4
+ const { padding } = useReactCake();
5
+ return (
6
+ <div
7
+ style={{
8
+ position: "absolute",
9
+ left: 0,
10
+ right: 0,
11
+ top: 0,
12
+ bottom: 0,
13
+ boxShadow: `${padding.right}px 0 var(--blue-20), 0 ${padding.bottom}px var(--blue-20), 0 ${-padding.top}px var(--blue-20), -${padding.left}px 0 var(--blue-20)`,
14
+ }}
15
+ ></div>
16
+ );
17
+ }
@@ -1,3 +1,7 @@
1
+ ---
2
+ import "./code.css"
3
+ ---
4
+
1
5
  <!doctype html>
2
6
  <html lang="en">
3
7
  <head>
@@ -24,12 +28,13 @@
24
28
  body {
25
29
  margin: 0;
26
30
  width: 100%;
27
- padding: 2rem 0;
28
- font-family: sans-serif;
29
- --blue-70: hsl(212, 70%, 26%);
30
- --blue-50: hsl(212, 70%, 36%);
31
- --blue-30: hsl(212, 50%, 76%);
32
- --blue-10: hsl(212, 40%, 97%);
31
+ padding: .5rem;
32
+ font-family: Georgia, 'Times New Roman', Times, serif;
33
+ --blue-70: hsl(220, 0%, 20%);
34
+ --blue-50: hsl(220, 0%, 36%);
35
+ --blue-30: hsl(220, 0%, 76%);
36
+ --blue-20: hsl(220, 0%, 92%);
37
+ --blue-10: hsl(220, 0%, 97%);
33
38
  --ms--1: .8rem
34
39
  }
35
40
 
@@ -38,17 +43,23 @@
38
43
  }
39
44
 
40
45
  .content {
46
+ border: 1px solid var(--blue-70);
41
47
  max-width: 40rem;
42
48
  line-height: 1.4;
43
- margin: 0 auto;
49
+ padding: 1rem;
50
+ border-right: 1px solid var(--blue-70);
44
51
  }
45
52
 
46
53
  p, li {
47
54
  letter-spacing: .002em;
48
55
  }
49
56
 
57
+ h1 {
58
+ font-weight: 900;
59
+ }
60
+
50
61
  h2 {
51
- margin-top: 2rem;
62
+ margin-top: 1rem;
52
63
  margin-bottom: .25rem;
53
64
  }
54
65
  h3 {
@@ -59,20 +70,13 @@
59
70
 
60
71
  p, ul, ol {
61
72
  margin-bottom: 1rem;
73
+ &:last-child {
74
+ margin-bottom: 0;
75
+ }
62
76
  }
63
77
 
64
78
  ul, ol {
65
79
  margin-left: 1em;
66
80
  }
67
81
 
68
-
69
- .astro-code {
70
- border-top: 1px solid lightgray;
71
- border-bottom: 1px solid lightgray;
72
- margin: 1rem 0;
73
- padding: 1em 0;
74
- line-height: 1.25;
75
- font-family: monospace;
76
- }
77
-
78
82
  </style>
@@ -0,0 +1,37 @@
1
+ .astro-code {
2
+ --astro-code-background: hsl(51, 62.5%, 93.7%);
3
+ --astro-code-token-comment: #666;
4
+ margin: 1em 0;
5
+ margin-top: .5em;
6
+ padding: .5em;
7
+ font-size: 12px;
8
+ line-height: 1.25;
9
+ font-family: monospace;
10
+ }
11
+
12
+
13
+ pre.astro-code .indent {
14
+ display: inline-block;
15
+ position: relative;
16
+ left: var(--indent-offset);
17
+ }
18
+
19
+ pre.astro-code .indent:empty {
20
+ height: 1lh;
21
+ vertical-align: bottom;
22
+ }
23
+
24
+ pre.astro-code .indent::before {
25
+ content: '';
26
+ position: absolute;
27
+ opacity: 0.5;
28
+ width: 1px;
29
+ height: 100%;
30
+ background-color: red;
31
+ }
32
+
33
+ pre.astro-code .line-number {
34
+ user-select: none;
35
+ color: #666;
36
+ margin-right: 2ch;
37
+ }
@@ -17,13 +17,13 @@ A headless chart framework for React inspired by [Layercake](https://layercake.g
17
17
  ## Installation
18
18
 
19
19
  ```bash
20
- npm install --save reactcake
20
+ npm install --save @awesomephant/reactcake
21
21
  ```
22
22
 
23
23
  ## Usage
24
24
 
25
25
  ```tsx
26
- import { ReactCake, Html, Svg } from "reactcake";
26
+ import { ReactCake, Html, Svg } from "@awesomephant/reactcake";
27
27
  import { scaleLinear, scaleBand } from "d3-scale"
28
28
 
29
29
  // Chart components live in your project
@@ -35,9 +35,11 @@ const data = [
35
35
  {year: 2026, value: 52}
36
36
  ];
37
37
 
38
+ // Use any d3 scale
38
39
  const xScale = scaleTime();
39
40
  const xScale = scaleBand();
40
41
 
42
+ // Build charts declaratively
41
43
  return (
42
44
  <ReactCake data={data} x="year" y="value" xScale={xScale} yScale={yScale}>
43
45
  <Html>
@@ -61,7 +63,7 @@ ReactCake is built on [D3](https://d3js.org/what-is-d3).
61
63
 
62
64
  ### Relationship to Layercake
63
65
 
64
- This project is an attempt to translate the overall approach and development ergonomics of the Layercake framework from Svelte to React. It does not aim for feature parity or identical API surfaces.
66
+ This project is an attempt to carefully translate the overall approach and development ergonomics of the Layercake framework from Svelte to React. It does not aim for feature parity or identical API surfaces.
65
67
 
66
68
 
67
69
  ### Prior work