@sprucelabs/spruce-heartwood-utils 38.17.3 → 38.17.4
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 +110 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -709,6 +709,32 @@ interface AnimationEmitter {
|
|
|
709
709
|
}
|
|
710
710
|
```
|
|
711
711
|
|
|
712
|
+
#### Quick Setup
|
|
713
|
+
|
|
714
|
+
1. **Install**
|
|
715
|
+
|
|
716
|
+
```sh
|
|
717
|
+
npm install @sprucelabs/spruce-heartwood-utils
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
2. **Create an emitter** — one per component tree, stable across renders:
|
|
721
|
+
|
|
722
|
+
```ts
|
|
723
|
+
import { SimpleEmitter } from '@sprucelabs/spruce-heartwood-utils'
|
|
724
|
+
|
|
725
|
+
const emitter = useMemo(() => new SimpleEmitter(), [])
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
3. **Wire to components and emit events** — pass the emitter to `Sizer` and/or `DelayedPlacer`, then signal layout changes:
|
|
729
|
+
|
|
730
|
+
```ts
|
|
731
|
+
// After a React render cycle completes:
|
|
732
|
+
await emitter.emit('did-render')
|
|
733
|
+
|
|
734
|
+
// After a viewport resize:
|
|
735
|
+
await emitter.emit('did-resize')
|
|
736
|
+
```
|
|
737
|
+
|
|
712
738
|
**Events:**
|
|
713
739
|
|
|
714
740
|
| Event | Who listens | Who emits | Meaning |
|
|
@@ -944,6 +970,44 @@ return <h1 ref={ref} className="your-heading hidden">Title</h1>
|
|
|
944
970
|
|
|
945
971
|
Wraps children in a div whose `height` is set via inline style to match the measured height of its content. Listens to `did-render` and `did-resize` events so it resizes whenever layout changes — enabling smooth CSS height transitions on content that would otherwise be `height: auto`. Emits `did-resize-content` so `DelayedPlacer` can re-place after a height change.
|
|
946
972
|
|
|
973
|
+
#### Quick Setup
|
|
974
|
+
|
|
975
|
+
1. **Install and add the required CSS**
|
|
976
|
+
|
|
977
|
+
```sh
|
|
978
|
+
npm install @sprucelabs/spruce-heartwood-utils
|
|
979
|
+
```
|
|
980
|
+
|
|
981
|
+
```css
|
|
982
|
+
.sizer {
|
|
983
|
+
transition: height 500ms ease;
|
|
984
|
+
overflow: hidden;
|
|
985
|
+
}
|
|
986
|
+
```
|
|
987
|
+
|
|
988
|
+
> Inside a Heartwood skill view this CSS is already provided — skip this step.
|
|
989
|
+
|
|
990
|
+
2. **Wrap your content** — `shouldHideOverflow` clips children during the height transition:
|
|
991
|
+
|
|
992
|
+
```tsx
|
|
993
|
+
import { Sizer, SimpleEmitter } from '@sprucelabs/spruce-heartwood-utils'
|
|
994
|
+
|
|
995
|
+
const emitter = useMemo(() => new SimpleEmitter(), [])
|
|
996
|
+
|
|
997
|
+
<Sizer emitter={emitter} shouldHideOverflow>
|
|
998
|
+
<YourContent />
|
|
999
|
+
</Sizer>
|
|
1000
|
+
```
|
|
1001
|
+
|
|
1002
|
+
3. **Signal layout changes** — emit after renders and on viewport resize; Sizer measures content and updates `style.height` automatically:
|
|
1003
|
+
|
|
1004
|
+
```ts
|
|
1005
|
+
await emitter.emit('did-render')
|
|
1006
|
+
await emitter.emit('did-resize')
|
|
1007
|
+
```
|
|
1008
|
+
|
|
1009
|
+
In tests, call `Settings.disableAnimations()` in `beforeEach` so height changes apply synchronously.
|
|
1010
|
+
|
|
947
1011
|
#### Props (`SizerProps`)
|
|
948
1012
|
|
|
949
1013
|
```ts
|
|
@@ -1038,6 +1102,52 @@ Positions a child element to match the location of its in-flow placeholder. Wrap
|
|
|
1038
1102
|
|
|
1039
1103
|
When `isEnabled={false}`, children render inline with no wrapper.
|
|
1040
1104
|
|
|
1105
|
+
#### Quick Setup
|
|
1106
|
+
|
|
1107
|
+
1. **Install and add the required CSS**
|
|
1108
|
+
|
|
1109
|
+
```sh
|
|
1110
|
+
npm install @sprucelabs/spruce-heartwood-utils
|
|
1111
|
+
```
|
|
1112
|
+
|
|
1113
|
+
```css
|
|
1114
|
+
.placer { position: relative; }
|
|
1115
|
+
.placer > * { position: absolute; }
|
|
1116
|
+
```
|
|
1117
|
+
|
|
1118
|
+
> Inside a Heartwood skill view this CSS is already provided — skip this step.
|
|
1119
|
+
|
|
1120
|
+
2. **Wrap your content** — `isEnabled`, `className`, and `isFocused` are all required:
|
|
1121
|
+
|
|
1122
|
+
```tsx
|
|
1123
|
+
import { DelayedPlacer, SimpleEmitter } from '@sprucelabs/spruce-heartwood-utils'
|
|
1124
|
+
|
|
1125
|
+
const emitter = useMemo(() => new SimpleEmitter(), [])
|
|
1126
|
+
|
|
1127
|
+
<DelayedPlacer
|
|
1128
|
+
className="placer__card"
|
|
1129
|
+
isEnabled={true}
|
|
1130
|
+
emitter={emitter}
|
|
1131
|
+
isFocused={() => true}
|
|
1132
|
+
>
|
|
1133
|
+
<YourCard />
|
|
1134
|
+
</DelayedPlacer>
|
|
1135
|
+
```
|
|
1136
|
+
|
|
1137
|
+
Pass `() => true` for `isFocused` when using outside Heartwood — placement is skipped when this returns false.
|
|
1138
|
+
|
|
1139
|
+
3. **Share the emitter with `Sizer`** when they are siblings so height changes automatically trigger re-placement:
|
|
1140
|
+
|
|
1141
|
+
```tsx
|
|
1142
|
+
<DelayedPlacer className="placer__card" isEnabled emitter={emitter} isFocused={isFocused}>
|
|
1143
|
+
<Sizer emitter={emitter} shouldHideOverflow>
|
|
1144
|
+
<YourContent />
|
|
1145
|
+
</Sizer>
|
|
1146
|
+
</DelayedPlacer>
|
|
1147
|
+
```
|
|
1148
|
+
|
|
1149
|
+
`DelayedPlacer` emits `did-place-cards` when placement is complete. Listen for it if you need to react after cards settle.
|
|
1150
|
+
|
|
1041
1151
|
#### Props (`DelayedPlacerProps`)
|
|
1042
1152
|
|
|
1043
1153
|
```ts
|