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 all commits
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
@@ -0,0 +1,32 @@
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { InputComponent } from './sb-input.component';

export default {
title: 'Preview/CSF3/WithPlayFunction',
component: InputComponent,
parameters: {
// disabled : Not compatible yet with csf3
storyshots: { disable: true },
},
};

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`);
},
};
@@ -0,0 +1,7 @@
import { Component } from '@angular/core';

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