Skip to content

Commit 95d7a1d

Browse files
Samuel ReedSculptor
authored andcommitted
docs: add CLAUDE.md with project instructions
Co-authored-by: Sculptor <sculptor@imbue.com>
1 parent 65637dd commit 95d7a1d

File tree

5 files changed

+81
-12
lines changed

5 files changed

+81
-12
lines changed

CLAUDE.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Commands
6+
7+
```bash
8+
# Install dependencies
9+
yarn
10+
11+
# Run tests with coverage
12+
yarn test
13+
14+
# Run tests in watch mode
15+
yarn unit
16+
17+
# Lint (ESLint + Flow)
18+
yarn lint
19+
20+
# Type check only
21+
yarn flow
22+
23+
# Build (transpile lib/ to build/)
24+
yarn build
25+
26+
# Run dev server with examples
27+
yarn dev
28+
29+
# Build examples for production
30+
yarn build-example
31+
```
32+
33+
Run a single test file:
34+
```bash
35+
npx jest __tests__/Resizable.test.js
36+
```
37+
38+
Run tests matching a pattern:
39+
```bash
40+
npx jest --testNamePattern="snapshot"
41+
```
42+
43+
## Architecture
44+
45+
This is a React component library providing resizable functionality via two main components:
46+
47+
### Core Components (`lib/`)
48+
49+
- **Resizable.js** - Stateless base component. Wraps a child element with draggable resize handles using `react-draggable`'s `DraggableCore`. Computes size changes from drag deltas, applies constraints, and invokes callbacks. Does not manage state - parent must set `width`/`height` props from callback data.
50+
51+
- **ResizableBox.js** - Stateful wrapper around `<Resizable>`. Manages width/height state internally and renders a `<div>` with those dimensions. Simpler API for common use cases.
52+
53+
- **propTypes.js** - Shared Flow types and PropTypes definitions. Exports `resizableProps` object and types like `ResizeHandleAxis`, `ResizeCallbackData`, etc.
54+
55+
- **utils.js** - Helper `cloneElement()` that merges `style` and `className` when cloning React elements.
56+
57+
### Key Implementation Details
58+
59+
- Resize handles are rendered as `<DraggableCore>` wrappers around handle elements
60+
- Handle positions: `'s'`, `'w'`, `'e'`, `'n'`, `'sw'`, `'nw'`, `'se'`, `'ne'`
61+
- The `runConstraints()` method applies min/max constraints and aspect ratio locking with slack tracking
62+
- Position tracking via `lastHandleRect` compensates for element repositioning during north/west drags
63+
- `transformScale` prop adjusts deltas when parent has CSS transform scaling
64+
65+
### Build Output
66+
67+
`yarn build` transpiles `lib/*.js` to `build/` and copies source files as `*.js.flow` for Flow consumers.
68+
69+
## Testing
70+
71+
Tests use Jest with Enzyme for shallow/mount rendering. Test files in `__tests__/` mirror the lib structure. Snapshot tests verify render output; unit tests verify resize behavior, constraint handling, and callback data.

__tests__/Resizable.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @flow
21
import React from 'react';
32
import {render, screen} from '@testing-library/react';
43
import renderer from 'react-test-renderer';

__tests__/ResizableBox.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @flow
21
import React from 'react';
32
import {render, screen, act} from '@testing-library/react';
43
import renderer from 'react-test-renderer';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
},
6666
"dependencies": {
6767
"prop-types": "15.x",
68-
"react-draggable": "^4.0.3"
68+
"react-draggable": "^4.5.0"
6969
},
7070
"peerDependencies": {
7171
"react": ">= 16.3",

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,10 +2453,10 @@ clone-deep@^4.0.1:
24532453
kind-of "^6.0.2"
24542454
shallow-clone "^3.0.0"
24552455

2456-
clsx@^1.1.1:
2457-
version "1.2.1"
2458-
resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.2.1.tgz#0ddc4a20a549b59c93a4116bb26f5294ca17dc12"
2459-
integrity sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==
2456+
clsx@^2.1.1:
2457+
version "2.1.1"
2458+
resolved "https://registry.yarnpkg.com/clsx/-/clsx-2.1.1.tgz#eed397c9fd8bd882bfb18deab7102049a2f32999"
2459+
integrity sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==
24602460

24612461
co@^4.6.0:
24622462
version "4.6.0"
@@ -5437,12 +5437,12 @@ react-dom@^18:
54375437
loose-envify "^1.1.0"
54385438
scheduler "^0.23.2"
54395439

5440-
react-draggable@^4.0.3:
5441-
version "4.4.5"
5442-
resolved "https://registry.yarnpkg.com/react-draggable/-/react-draggable-4.4.5.tgz#9e37fe7ce1a4cf843030f521a0a4cc41886d7e7c"
5443-
integrity sha512-OMHzJdyJbYTZo4uQE393fHcqqPYsEtkjfMgvCHr6rejT+Ezn4OZbNyGH50vv+SunC1RMvwOTSWkEODQLzw1M9g==
5440+
react-draggable@^4.5.0:
5441+
version "4.5.0"
5442+
resolved "https://registry.yarnpkg.com/react-draggable/-/react-draggable-4.5.0.tgz#0b274ccb6965fcf97ed38fcf7e3cc223bc48cdf5"
5443+
integrity sha512-VC+HBLEZ0XJxnOxVAZsdRi8rD04Iz3SiiKOoYzamjylUcju/hP9np/aZdLHf/7WOD268WMoNJMvYfB5yAK45cw==
54445444
dependencies:
5445-
clsx "^1.1.1"
5445+
clsx "^2.1.1"
54465446
prop-types "^15.8.1"
54475447

54485448
"react-is@^16.12.0 || ^17.0.0 || ^18.0.0", react-is@^18.3.1:

0 commit comments

Comments
 (0)