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

[Bug]: Angular Decorator standalone #23937

Closed
walkadaw opened this issue Aug 24, 2023 · 3 comments · Fixed by #24448
Closed

[Bug]: Angular Decorator standalone #23937

walkadaw opened this issue Aug 24, 2023 · 3 comments · Fixed by #24448

Comments

@walkadaw
Copy link

walkadaw commented Aug 24, 2023

Describe the bug

export default {
  title: 'Components/Tooltip',
  component: KTooltipDirective, // standalone directive
}

Error: Unexpected "KTooltipDirective" found in the "declarations" array of the "StorybookComponentModule" NgModule, "KTooltipDirective" is marked as standalone and can't be declared in any NgModule - did you intend to import it instead (by adding it to the "imports" array)?

static analyzeDecorators = (component: any) => {
const decorators = reflectionCapabilities.annotations(component);
const isComponent = decorators.some((d) => this.isDecoratorInstanceOf(d, 'Component'));
const isDirective = decorators.some((d) => this.isDecoratorInstanceOf(d, 'Directive'));
const isPipe = decorators.some((d) => this.isDecoratorInstanceOf(d, 'Pipe'));
const isDeclarable = isComponent || isDirective || isPipe;
const isStandalone = isComponent && decorators.some((d) => d.standalone);
return { isDeclarable, isStandalone };
};

it looks like we should allow standalone directive

const isStandalone = (isComponent || isDirective) && decorators.some((d) => d.standalone);

it is work but I lose all control information

export default {
  title: 'Components/Tooltip',
  decorators: [
    moduleMetadata({
      imports: [KTooltipDirective],
    }),
  ],

The main problem is that we want to receive data for controls from directives, but if we do not specify them in the component, then we do not receive them.

To Reproduce

https://stackblitz.com/edit/github-mz24pf?file=src%2Fstories%2Fissue.stories.ts,package.json&preset=node

System

System:
    OS: Windows 10 10.0.22621
    CPU: (4) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
  Binaries:
    Node: 18.12.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 8.19.3 - C:\git\jb-design-system\node_modules\.bin\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.2134.0), Chromium (116.0.1938.54)
  npmPackages:
    @storybook/addon-actions: ^7.3.2 => 7.3.2
    @storybook/addon-essentials: ^7.3.2 => 7.3.2
    @storybook/addon-interactions: ^7.3.2 => 7.3.2
    @storybook/addon-links: ^7.3.2 => 7.3.2
    @storybook/addon-mdx-gfm: ^7.3.2 => 7.3.2
    @storybook/angular: ^7.3.2 => 7.3.2
    @storybook/testing-library: ^0.2.0 => 0.2.0
    @storybook/theming: ^7.3.2 => 7.3.2

Additional context

No response

@thibaudsowa
Copy link

I have the exact same problem. With the component attribut: error but I have controls, without: no error, but no controls :(

@osnoser1
Copy link
Contributor

I have the same problem

@osnoser1
Copy link
Contributor

I sent a PR with the suggested changes by @walkadaw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants