Skip to content

Commit

Permalink
refactor(ngx-components)!: completely switch to standalone (#2184)
Browse files Browse the repository at this point in the history
* refactor(ngx-components)!: completely switch to standalone

BREAKING CHANGE:
All Angular components are `standalone` now.
SCAM (Single Component Angular Modules) have been removed.
please import the standalone components directly in your `imports` section.

```ts app.component.ts
//app.component.ts
import { DBButton } from '@db-ui/ngx-components';

@component({
	// ...
	imports: [
		// ...,
		DBButton
    ],
	// ...
})
```

closes #237

* fix: use withHashLocation

* fix: add missing NavigationContentDirective import

* fix: add missing NavigationContentDirective import

* fix: remove --ui flag from test

* fix: add standalone for angular mitosis specific config as well
  • Loading branch information
d-koppenhagen authored Feb 8, 2024
1 parent 729810a commit 0efa2a2
Show file tree
Hide file tree
Showing 107 changed files with 696 additions and 697 deletions.
20 changes: 11 additions & 9 deletions output/angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ Import the styles in scss or css. Based on your technology the file names could

## Usage

```ts app.module.ts
//app.module.ts
import { DBButtonModule } from '@db-ui/ngx-components';

@NgModule({
...
imports: [..., DBButtonModule],
...
})
```ts app.component.ts
//app.component.ts
import { DBButton } from '@db-ui/ngx-components';

@Component({
// ...
imports: [
// ...,
DBButton
],
// ...
})
```

```html app.component.html
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
to: overrides/angular/src/components/<%= name %>/index.ts
---
export { DB<%= h.changeCase.pascal(name) %>, DB<%= h.changeCase.pascal(name) %>Module } from "./<%= name %>";
export { DB<%= h.changeCase.pascal(name) %> } from "./<%= name %>";
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ to: "<%= showcases ? `../../showcases/angular-showcase/src/app/components/${name
---
import { Component } from '@angular/core';

import { DefaultComponent } from '../default.component';
import defaultComponentVariants from '../../../../../shared/<%= name %>.json';

@Component({
selector: 'app-<%= name %>',
templateUrl: './<%= name %>.component.html'
templateUrl: './<%= name %>.component.html',
imports: [DefaultComponent],
standalone: true
})
export class <%= h.changeCase.pascal(name) %>Component {
variants = defaultComponentVariants;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 2 additions & 1 deletion packages/components/mitosis-angular.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = {
dest: '../../output/tmp',
options: {
angular: {
typescript: true
typescript: true,
standalone: true
}
}
};
3 changes: 2 additions & 1 deletion packages/components/mitosis.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module.exports = {
typescript: true
},
angular: {
typescript: true
typescript: true,
standalone: true
},
vue3: {
typescript: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBAccordionItem, DBAccordionItemModule } from './accordion-item';
export { DBAccordionItem } from './accordion-item';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBAccordion, DBAccordionModule } from './accordion';
export { DBAccordion } from './accordion';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBAlert, DBAlertModule } from './alert';
export { DBAlert } from './alert';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBBadge, DBBadgeModule } from './badge';
export { DBBadge } from './badge';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBBrand, DBBrandModule } from './brand';
export { DBBrand } from './brand';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBButton, DBButtonModule } from './button';
export { DBButton } from './button';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBCard, DBCardModule } from './card';
export { DBCard } from './card';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBCheckbox, DBCheckboxModule } from './checkbox';
export { DBCheckbox } from './checkbox';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBCodeDocs, DBCodeDocsModule } from './code-docs';
export { DBCodeDocs } from './code-docs';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBDivider, DBDividerModule } from './divider';
export { DBDivider } from './divider';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBDrawer, DBDrawerModule } from './drawer';
export { DBDrawer } from './drawer';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBHeader, DBHeaderModule } from './header';
export { DBHeader } from './header';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBIcon, DBIconModule } from './icon';
export { DBIcon } from './icon';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBInfotext, DBInfotextModule } from './infotext';
export { DBInfotext } from './infotext';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBInput, DBInputModule } from './input';
export { DBInput } from './input';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBLink, DBLinkModule } from './link';
export { DBLink } from './link';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBMainNavigation, DBMainNavigationModule } from './main-navigation';
export { DBMainNavigation } from './main-navigation';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBNavigationItem, DBNavigationItemModule } from './navigation-item';
export { DBNavigationItem } from './navigation-item';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBPage, DBPageModule } from './page';
export { DBPage } from './page';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBPopover, DBPopoverModule } from './popover';
export { DBPopover } from './popover';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBRadio, DBRadioModule } from './radio';
export { DBRadio } from './radio';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBSection, DBSectionModule } from './section';
export { DBSection } from './section';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBSelect, DBSelectModule } from './select';
export { DBSelect } from './select';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBSubNavigation, DBSubNavigationModule } from './sub-navigation';
export { DBSubNavigation } from './sub-navigation';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBTabBar, DBTabBarModule } from './tab-bar';
export { DBTabBar } from './tab-bar';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBTab, DBTabModule } from './tab';
export { DBTab } from './tab';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBTag, DBTagModule } from './tag';
export { DBTag } from './tag';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBTextarea, DBTextareaModule } from './textarea';
export { DBTextarea } from './textarea';
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DBTooltip, DBTooltipModule } from './tooltip';
export { DBTooltip } from './tooltip';
23 changes: 8 additions & 15 deletions packages/components/scripts/post-build/angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ const changeFile = (component, input) => {
!line.includes(`[key]=`)
)
.map((line) => {
if (
line.includes(`import { DB`) &&
line.includes(`../`) &&
!line.includes(`Module`)
) {
return line.replace(` } from "../`, `Module } from "../`);
}

if (line.includes(': ElementRef')) {
return line.replace(': ElementRef', ': ElementRef | undefined');
}
Expand Down Expand Up @@ -59,7 +51,7 @@ const setControlValueAccessorReplacements = (
replacements.push({
from: '} from "@angular/core";',
to:
`, Renderer2 } from "@angular/core";\n` +
`Renderer2 } from "@angular/core";\n` +
`import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';\n`
});

Expand Down Expand Up @@ -148,10 +140,10 @@ const setDirectiveReplacements = (
});

replacements.push({
from: 'import { NgModule } from "@angular/core";',
from: '@Component({',
to:
'import { NgModule } from "@angular/core";\n' +
`import { ${directive.name}Directive } from './${directive.name}.directive';\n`
`import { ${directive.name}Directive } from './${directive.name}.directive';\n\n` +
'@Component({'
});

FS.writeFileSync(
Expand All @@ -160,16 +152,17 @@ const setDirectiveReplacements = (
"import { Directive } from '@angular/core';" +
`
@Directive({
\tselector: '[db${directive.name}]'
\tselector: '[db${directive.name}]',
\tstandalone: true
})
export class ${directive.name}Directive {}
`
);
}

replacements.push({
from: 'import { NgModule } from "@angular/core";',
to: "import { NgModule, ContentChild, TemplateRef } from '@angular/core';"
from: '} from "@angular/core";',
to: 'ContentChild, TemplateRef } from "@angular/core";'
});
};

Expand Down
9 changes: 7 additions & 2 deletions packages/components/scripts/post-build/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,17 @@ const getComponents = () => [
config: {
angular: {
directives: [
{ name: 'ActionBar', ngContentName: 'action-bar' },
{
name: 'ActionBar',
ngContentName: 'action-bar'
},
{
name: 'MetaNavigation',
ngContentName: 'meta-navigation'
},
{ name: 'Navigation' }
{
name: 'Navigation'
}
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ For general installation and configuration look at the [ngx-components](https://

```ts app.component.ts
// app.component.ts
import { DBAccordionItemModule } from '@db-ui/ngx-components';
import { DBAccordionItem } from '@db-ui/ngx-components';

@Component({
// ...
standalone: true,
imports: [..., DBAccordionItemModule],
imports: [..., DBAccordionItem],
// ...
})
```
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/components/accordion/docs/Angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ For general installation and configuration look at the [ngx-components](https://

```ts app.component.ts
// app.component.ts
import { DBAccordionModule } from '@db-ui/ngx-components';
import { DBAccordion } from '@db-ui/ngx-components';

@Component({
// ...
standalone: true,
imports: [..., DBAccordionModule],
imports: [..., DBAccordion],
// ...
})
```
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/components/alert/docs/Angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ For general installation and configuration take a look at the [ngx-components](h

```ts app.component.ts
// app.component.ts
import { DBAlertModule } from '@db-ui/ngx-components';
import { DBAlert } from '@db-ui/ngx-components';

@Component({
// ...
standalone: true,
imports: [..., DBAlertModule],
imports: [..., DBAlert],
// ...
})
```
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/components/badge/docs/Angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ For general installation and configuration take a look at the [ngx-components](h

```ts app.component.ts
// app.component.ts
import { DBBadgeModule } from '@db-ui/ngx-components';
import { DBBadge } from '@db-ui/ngx-components';

@Component({
// ...
standalone: true,
imports: [..., DBBadgeModule],
imports: [..., DBBadge],
// ...
})
```
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/components/brand/docs/Angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ For general installation and configuration take a look at the [ngx-components](h

```ts app.component.ts
// app.component.ts
import { DBBrandModule } from '@db-ui/ngx-components';
import { DBBrand } from '@db-ui/ngx-components';

@Component({
// ...
standalone: true,
imports: [..., DBBrandModule],
imports: [..., DBBrand],
// ...
})
```
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/components/button/docs/Angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ For general installation and configuration take a look at the [ngx-components](h

```ts app.component.ts
// app.component.ts
import { DBButtonModule } from '@db-ui/ngx-components';
import { DBButton } from '@db-ui/ngx-components';

@Component({
// ...
standalone: true,
imports: [..., DBButtonModule],
imports: [..., DBButton],
// ...
})
```
Expand Down
17 changes: 10 additions & 7 deletions packages/components/src/components/card/docs/Angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ For general installation and configuration take a look at the [ngx-components](h

### Load component

```ts app.module.ts
//app.module.ts
import { DBCardModule } from '@db-ui/ngx-components';
```ts app.component.ts
//app.component.ts
import { DBCard } from '@db-ui/ngx-components';

@NgModule({
...
imports: [..., DBCardModule],
...
@Component({
// ...
imports: [
// ...,
DBCard
],
// ...
})
```

Expand Down
Loading

0 comments on commit 0efa2a2

Please sign in to comment.