Skip to content

Commit 307cd41

Browse files
Chau TranChau Tran
Chau Tran
authored and
Chau Tran
committed
feat(soba): migrate sky and refactor stories
1 parent 9b66b44 commit 307cd41

File tree

12 files changed

+388
-101
lines changed

12 files changed

+388
-101
lines changed

libs/soba/src/abstractions/billboard.stories.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Component, CUSTOM_ELEMENTS_SCHEMA, Input } from '@angular/core';
2-
import { Meta, moduleMetadata, StoryObj } from '@storybook/angular';
2+
import { Meta, moduleMetadata } from '@storybook/angular';
33
import { NgtArgs } from 'angular-three';
44
import { NgtsBillboard, NgtsText } from 'angular-three-soba/abstractions';
55
import { NgtsOrbitControls } from 'angular-three-soba/controls';
66
import { BoxGeometry, ConeGeometry, PlaneGeometry } from 'three';
7-
import { makeRenderFunction, StorybookSetup } from '../setup-canvas';
7+
import { makeStoryObject, StorybookSetup } from '../setup-canvas';
88

99
@Component({
1010
selector: 'BillboardCone',
@@ -138,17 +138,13 @@ export default {
138138
decorators: [moduleMetadata({ imports: [StorybookSetup] })],
139139
} as Meta;
140140

141-
const canvasOptions = {
142-
camera: { position: [0, 0, 10] },
143-
controls: false,
144-
};
141+
const canvasOptions = { camera: { position: [0, 0, 10] }, controls: false };
145142

146-
export const Default: StoryObj = {
147-
render: makeRenderFunction(DefaultBillboardStory, canvasOptions),
148-
args: { follow: true, lockX: false, lockY: false, lockZ: false },
149-
};
150-
151-
export const Text: StoryObj = {
152-
render: makeRenderFunction(TextBillboardStory, canvasOptions),
153-
args: { follow: true, lockX: false, lockY: false, lockZ: false },
154-
};
143+
export const Default = makeStoryObject(DefaultBillboardStory, {
144+
canvasOptions,
145+
argsOptions: { follow: true, lockX: false, lockY: false, lockZ: false },
146+
});
147+
export const Text = makeStoryObject(TextBillboardStory, {
148+
canvasOptions,
149+
argsOptions: { follow: true, lockX: false, lockY: false, lockZ: false },
150+
});

libs/soba/src/abstractions/line.stories.ts

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, CUSTOM_ELEMENTS_SCHEMA, Input } from '@angular/core';
2-
import { Meta, moduleMetadata, StoryObj } from '@storybook/angular';
2+
import { Meta, moduleMetadata } from '@storybook/angular';
33
import {
44
NgtsCatmullRomLine,
55
NgtsCubicBezierLine,
@@ -9,7 +9,7 @@ import {
99
import { NgtsOrbitControls } from 'angular-three-soba/controls';
1010
import * as THREE from 'three';
1111
import { GeometryUtils } from 'three-stdlib';
12-
import { makeRenderFunction, StorybookSetup } from '../setup-canvas';
12+
import { color, makeStoryObject, number, select, StorybookSetup } from '../setup-canvas';
1313

1414
const points = GeometryUtils.hilbert3D(new THREE.Vector3(0), 5).map((p) => [p.x, p.y, p.z]) as [
1515
number,
@@ -186,30 +186,39 @@ export default {
186186

187187
const canvasOptions = { camera: { position: [0, 0, 17] }, controls: false };
188188

189-
export const Default: StoryObj = {
190-
render: makeRenderFunction(DefaultLineStory, canvasOptions),
191-
args: { color: 'red', dashed: false, lineWidth: 3 },
192-
};
193-
194-
export const VertexColors: StoryObj = {
195-
render: makeRenderFunction(VertexColorsLineStory, canvasOptions),
196-
args: { color: 'red', dashed: false, lineWidth: 3 },
197-
};
198-
199-
export const CubicBezierLine: StoryObj = {
200-
render: makeRenderFunction(CubicBezierLineStory, canvasOptions),
201-
args: { ...defaultCubicBezier, color: 'red', lineWidth: 3, dashed: false },
202-
};
203-
204-
export const QuadraticBezierLine: StoryObj = {
205-
render: makeRenderFunction(QuadraticBezierLineStory, canvasOptions),
206-
args: { ...defaultQuadraticBezier, color: 'red', lineWidth: 3, dashed: false },
207-
};
208-
209-
export const CatmullRomLine: StoryObj = {
210-
render: makeRenderFunction(CatmullRomLineStory, canvasOptions),
211-
args: { ...defaultCatmullRom, color: 'red', lineWidth: 3, dashed: false },
212-
argTypes: {
213-
curveType: { options: ['centripetal', 'chordal', 'catmullrom'], control: { type: 'select' } },
189+
export const Default = makeStoryObject(DefaultLineStory, {
190+
canvasOptions,
191+
argsOptions: { color: color('red'), dashed: false, lineWidth: number(3, { range: true, max: 10, step: 0.5 }) },
192+
});
193+
export const VertexColors = makeStoryObject(VertexColorsLineStory, {
194+
canvasOptions,
195+
argsOptions: { dashed: false, lineWidth: number(3, { range: true, max: 10, step: 0.5 }) },
196+
});
197+
export const CubicBezierLine = makeStoryObject(CubicBezierLineStory, {
198+
canvasOptions,
199+
argsOptions: {
200+
...defaultCubicBezier,
201+
color: color('red'),
202+
dashed: false,
203+
lineWidth: number(3, { range: true, max: 10, step: 0.5 }),
214204
},
215-
};
205+
});
206+
export const QuadraticBezierLine = makeStoryObject(QuadraticBezierLineStory, {
207+
canvasOptions,
208+
argsOptions: {
209+
...defaultQuadraticBezier,
210+
color: color('red'),
211+
dashed: false,
212+
lineWidth: number(3, { range: true, max: 10, step: 0.5 }),
213+
},
214+
});
215+
export const CatmullRomLine = makeStoryObject(CatmullRomLineStory, {
216+
canvasOptions,
217+
argsOptions: {
218+
...defaultCatmullRom,
219+
color: color('red'),
220+
dashed: false,
221+
lineWidth: number(3, { range: true, max: 10, step: 0.5 }),
222+
curveType: select(defaultCatmullRom.curveType, { options: ['centripetal', 'chordal', 'catmullrom'] }),
223+
},
224+
});

libs/soba/src/abstractions/text-3d.stories.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Component, CUSTOM_ELEMENTS_SCHEMA, Input } from '@angular/core';
2-
import { Meta, moduleMetadata, StoryObj } from '@storybook/angular';
2+
import { Meta, moduleMetadata } from '@storybook/angular';
33
import { NgtsText3D } from 'angular-three-soba/abstractions';
44
import { NgtsCenter, NgtsFloat } from 'angular-three-soba/staging';
5-
import { makeRenderFunction, StorybookSetup } from '../setup-canvas';
5+
import { makeStoryObject, StorybookSetup } from '../setup-canvas';
66

77
@Component({
88
standalone: true,
@@ -32,7 +32,7 @@ export default {
3232
decorators: [moduleMetadata({ imports: [StorybookSetup] })],
3333
} as Meta;
3434

35-
export const Default: StoryObj = {
36-
render: makeRenderFunction(DefaultText3DStory, { camera: { position: [0, 0, 10] } }),
37-
args: { text: 'Angular Three' },
38-
};
35+
export const Default = makeStoryObject(DefaultText3DStory, {
36+
canvasOptions: { camera: { position: [0, 0, 10] } },
37+
argsOptions: { text: 'Angular Three' },
38+
});

libs/soba/src/abstractions/text.stories.ts

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Component, CUSTOM_ELEMENTS_SCHEMA, Input } from '@angular/core';
2-
import { Meta, moduleMetadata, StoryObj } from '@storybook/angular';
2+
import { Meta, moduleMetadata } from '@storybook/angular';
33
import { NgtsText } from 'angular-three-soba/abstractions';
44
import { DoubleSide } from 'three';
5-
import { makeRenderFunction, StorybookSetup, turn } from '../setup-canvas';
5+
import { color, makeStoryObject, StorybookSetup, turn } from '../setup-canvas';
66

77
@Component({
88
standalone: true,
@@ -180,34 +180,23 @@ EXCEPTEUR SINT OCCAECAT CUPIDATAT NON PROIDENT, SUNT IN CULPA QUI OFFICIA DESERU
180180

181181
const canvasOptions = { camera: { position: [0, 0, 200] } };
182182

183-
export const Default: StoryObj = {
184-
render: makeRenderFunction(DefaultTextStory, canvasOptions),
185-
args: { text: defaultText, color: '#ec2d2d' },
186-
};
187-
188-
export const Outline: StoryObj = {
189-
render: makeRenderFunction(OutlineTextStory, canvasOptions),
190-
args: { text: defaultText },
191-
};
192-
193-
export const Stroke: StoryObj = {
194-
render: makeRenderFunction(StrokeTextStory, canvasOptions),
195-
args: { text: defaultText },
196-
};
197-
198-
export const Shadow: StoryObj = {
199-
render: makeRenderFunction(ShadowTextStory, canvasOptions),
200-
args: { text: defaultText },
201-
};
202-
203-
export const LTR: StoryObj = {
204-
render: makeRenderFunction(LTRTextStory, canvasOptions),
205-
args: {
183+
export const Default = makeStoryObject(DefaultTextStory, {
184+
canvasOptions,
185+
argsOptions: { text: defaultText, color: color('#ec2d2d') },
186+
});
187+
export const Outline = makeStoryObject(OutlineTextStory, { canvasOptions, argsOptions: { text: defaultText } });
188+
export const Stroke = makeStoryObject(StrokeTextStory, { canvasOptions, argsOptions: { text: defaultText } });
189+
export const Shadow = makeStoryObject(ShadowTextStory, { canvasOptions, argsOptions: { text: defaultText } });
190+
export const LTR = makeStoryObject(LTRTextStory, {
191+
canvasOptions,
192+
argsOptions: {
206193
text: `يولد جميع الناس أحرارًا متساوين في الكرامة والحقوق. وقد وهبوا عقلاً وضميرًا وعليهم أن يعامل بعضهم بعضًا بروح الإخاء.`,
207194
},
208-
};
209-
210-
export const CustomMaterial: StoryObj = {
211-
render: makeRenderFunction(CustomMaterialTextStory, canvasOptions),
212-
args: { text: defaultText, color: 'turquoise' },
213-
};
195+
});
196+
export const CustomMaterial = makeStoryObject(CustomMaterialTextStory, {
197+
canvasOptions,
198+
argsOptions: {
199+
text: defaultText,
200+
color: color('turquoise'),
201+
},
202+
});

libs/soba/src/performance/adaptive.stories.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { NgIf } from '@angular/common';
22
import { CUSTOM_ELEMENTS_SCHEMA, Component, Signal } from '@angular/core';
3-
import { Meta, StoryFn, moduleMetadata } from '@storybook/angular';
3+
import { Meta, moduleMetadata } from '@storybook/angular';
44
import { NgtArgs } from 'angular-three';
55
import { NgtsOrbitControls } from 'angular-three-soba/controls';
66
import { injectNgtsGLTFLoader } from 'angular-three-soba/loaders';
77
import { NgtsAdaptiveDpr, NgtsAdaptiveEvents } from 'angular-three-soba/performance';
88
import type { Material, Mesh } from 'three';
99
import type { GLTF } from 'three-stdlib/loaders/GLTFLoader';
10-
import { StorybookSetup, makeRenderFunction } from '../setup-canvas';
10+
import { StorybookSetup, makeStoryFunction } from '../setup-canvas';
1111

1212
interface ArcherGLTF extends GLTF {
1313
materials: { material_0: Material };
@@ -73,7 +73,7 @@ export default {
7373
decorators: [moduleMetadata({ imports: [StorybookSetup] })],
7474
} as Meta;
7575

76-
export const Default: StoryFn = makeRenderFunction(DefaultAdaptiveStory, {
76+
export const Default = makeStoryFunction(DefaultAdaptiveStory, {
7777
camera: { position: [0, 0, 30], fov: 50 },
7878
controls: false,
7979
lights: false,

libs/soba/src/performance/detailed.stories.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Meta, moduleMetadata, StoryFn } from '@storybook/angular';
33
import { NgtArgs } from 'angular-three';
44
import { NgtsOrbitControls } from 'angular-three-soba/controls';
55
import { NgtsDetailed } from 'angular-three-soba/performance';
6-
import { makeRenderFunction, StorybookSetup } from '../setup-canvas';
6+
import { makeStoryFunction, StorybookSetup } from '../setup-canvas';
77

88
@Component({
99
standalone: true,
@@ -36,7 +36,7 @@ export default {
3636
decorators: [moduleMetadata({ imports: [StorybookSetup] })],
3737
} as Meta;
3838

39-
export const Default: StoryFn = makeRenderFunction(DefaultDetailedStory, {
39+
export const Default: StoryFn = makeStoryFunction(DefaultDetailedStory, {
4040
controls: false,
4141
camera: { position: [0, 0, 100] },
4242
});

libs/soba/src/setup-canvas.ts

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,58 @@ export function makeCanvasOptions(options: DeepPartial<CanvasOptions> = {}) {
208208
return mergedOptions;
209209
}
210210

211-
export function makeRenderFunction(story: Type<unknown>, canvasOptions: DeepPartial<CanvasOptions> = {}) {
211+
export function makeStoryFunction(story: Type<unknown>, canvasOptions: DeepPartial<CanvasOptions> = {}) {
212212
return (args: Args) => {
213213
return {
214-
props: {
215-
options: makeCanvasOptions(canvasOptions),
216-
inputs: args || {},
217-
story,
218-
},
214+
props: { options: makeCanvasOptions(canvasOptions), inputs: args || {}, story },
219215
template: `<storybook-setup [story]="story" [inputs]="inputs" [options]="options" />`,
220216
};
221217
};
222218
}
223219

220+
export function makeStoryObject(
221+
story: Type<unknown>,
222+
{
223+
canvasOptions = {},
224+
argsOptions = {},
225+
}: {
226+
canvasOptions?: DeepPartial<CanvasOptions>;
227+
argsOptions?: Record<string, any | { defaultValue: any; control: { control: any } }>;
228+
} = {}
229+
) {
230+
const render = makeStoryFunction(story, canvasOptions);
231+
const args: Record<string, any> = {};
232+
const argTypes: Record<string, any> = {};
233+
234+
for (const [argKey, argOption] of Object.entries(argsOptions)) {
235+
if (argOption['defaultValue']) {
236+
args[argKey] = argOption.defaultValue;
237+
argTypes[argKey] = argOption.control;
238+
} else {
239+
args[argKey] = argOption;
240+
}
241+
}
242+
243+
return { render, args, argTypes };
244+
}
245+
246+
export function number(
247+
defaultValue: number,
248+
options: { min?: number; max?: number; step?: number; range?: true } = {}
249+
) {
250+
if (Object.keys(options).length === 0) return defaultValue;
251+
const { range, ...rest } = options;
252+
return { defaultValue, control: { control: { type: range ? 'range' : 'number', ...rest } } };
253+
}
254+
255+
export function color(defaultValue: string, { presetColors = [] }: { presetColors?: THREE.ColorKeyword[] } = {}) {
256+
return { defaultValue, control: { control: { type: 'color', presetColors } } };
257+
}
258+
259+
export function select(defaultValue: string | string[], { multi, options }: { options: string[]; multi?: true }) {
260+
return { defaultValue, control: { control: multi ? 'multi-select' : 'select', options } };
261+
}
262+
224263
export function turn(object: THREE.Object3D) {
225264
object.rotation.y += 0.01;
226265
}

libs/soba/src/staging/cloud.stories.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
2-
import { Meta, moduleMetadata, StoryFn } from '@storybook/angular';
2+
import { Meta, moduleMetadata } from '@storybook/angular';
33
import { NgtsOrbitControls } from 'angular-three-soba/controls';
44
import { NgtsCloud } from 'angular-three-soba/staging';
5-
import { makeRenderFunction, StorybookSetup } from '../setup-canvas';
5+
import { makeStoryFunction, StorybookSetup } from '../setup-canvas';
66

77
@Component({
88
standalone: true,
@@ -24,7 +24,7 @@ export default {
2424
decorators: [moduleMetadata({ imports: [StorybookSetup] })],
2525
} as Meta;
2626

27-
export const Default: StoryFn = makeRenderFunction(DefaultCloudStory, {
27+
export const Default = makeStoryFunction(DefaultCloudStory, {
2828
camera: { position: [0, 0, 10] },
2929
controls: false,
3030
});

libs/soba/src/staging/contact-shadows.stories.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Component, CUSTOM_ELEMENTS_SCHEMA, Input } from '@angular/core';
2-
import { Meta, moduleMetadata, StoryFn, StoryObj } from '@storybook/angular';
2+
import { Meta, moduleMetadata } from '@storybook/angular';
33
import { NgtArgs, type NgtBeforeRenderEvent } from 'angular-three';
44
import { NgtsContactShadows } from 'angular-three-soba/staging';
5-
import { makeRenderFunction, StorybookSetup } from '../setup-canvas';
5+
import { makeStoryFunction, makeStoryObject, StorybookSetup } from '../setup-canvas';
66

77
@Component({
88
standalone: true,
@@ -41,8 +41,7 @@ export default {
4141
decorators: [moduleMetadata({ imports: [StorybookSetup] })],
4242
} as Meta;
4343

44-
export const Default: StoryFn = makeRenderFunction(DefaultContactShadowsStory);
45-
export const Colorized: StoryObj = {
46-
render: makeRenderFunction(DefaultContactShadowsStory),
47-
args: { colorized: true },
48-
};
44+
export const Default = makeStoryFunction(DefaultContactShadowsStory);
45+
export const Colorized = makeStoryObject(DefaultContactShadowsStory, {
46+
argsOptions: { colorized: true },
47+
});

0 commit comments

Comments
 (0)