Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular: Add global CSF3 renderer #15742

Merged
merged 5 commits into from Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/angular/src/client/preview/index.ts
@@ -1,11 +1,11 @@
/* eslint-disable prefer-destructuring */
import { RenderStoryFunction, start } from '@storybook/core/client';
import { ClientStoryApi, Loadable } from '@storybook/addons';

import { RenderStoryFunction, start } from '@storybook/core/client';
import decorateStory from './decorateStory';
import './globals';
import render from './render';
import decorateStory from './decorateStory';
import { IStorybookSection, StoryFnAngularReturnType } from './types';
import { Story } from './types-6-0';

const framework = 'angular';

Expand All @@ -19,8 +19,11 @@ interface ClientApi extends ClientStoryApi<StoryFnAngularReturnType> {
load: (...args: any[]) => void;
}

const globalRender: Story = (props) => ({ props });

const api = start((render as any) as RenderStoryFunction, { decorateStory });

api.clientApi.globalRender = globalRender;
export const storiesOf: ClientApi['storiesOf'] = (kind, m) => {
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({
framework,
Expand Down
3 changes: 3 additions & 0 deletions examples/angular-cli/.storybook/main.js
Expand Up @@ -19,6 +19,9 @@ module.exports = {
angularOptions: {
enableIvy: true,
},
features: {
previewCsfV3: true,
},
// These are just here to test composition. They could be added to any storybook example project
refs: {
first: {
Expand Down
28 changes: 28 additions & 0 deletions examples/angular-cli/src/stories/csf3/input-with-play.stories.ts
@@ -0,0 +1,28 @@
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { InputComponent } from './sb-input.component';

export default {
title: 'CSF3/Input',
Copy link
Contributor

@ThibaudAV ThibaudAV Aug 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe Core / CSF3 / Input ? Or Beta / ... 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would "Preview" be a fitting prefix perhaps?

Copy link
Contributor

@ThibaudAV ThibaudAV Aug 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • In core I tried to place the stories showing and testing the native functionality of sotrybook
  • basics it's more for examples of storybook use or helpers or common examples
  • addons for addons
    ..
    so if CSF3 is to become something native in storybook main set, I can see it in core/...

but it's up to you, knowing that ;)

component: InputComponent,
};

export const Default = {
title: 'Default',
play: async () => {
const input = await screen.getByAltText('sb-input');
await userEvent.type(input, `Typing from CSF3`);
},
};

export const WithTemplate = {
title: 'Template',
render: (props) => ({
props,
template: '<h1>Heading</h1><sb-input></sb-input>',
}),
play: async () => {
const input = await screen.getByAltText('sb-input');
await userEvent.type(input, `Typing from CSF3`);
},
};
7 changes: 7 additions & 0 deletions examples/angular-cli/src/stories/csf3/sb-input.component.ts
@@ -0,0 +1,7 @@
import { Component } from '@angular/core';

@Component({
selector: 'sb-input',
template: `<input type="text" alt="sb-input" />`,
})
export class InputComponent {}