Comments (3)
Thanks for opening this! I am looking into how to best implement this.
What would you like the template of the MyDialogComponent to look like?
The_ only way to show a dialog is to have both dialog and trigger in the same template.
It is possible to bind to the state input of the dialog.
Here is an example:
@Component({
selector: 'combobox-component',
standalone: true,
imports: [
NgForOf,
BrnCommandImports,
HlmCommandImports,
BrnPopoverImports,
HlmPopoverContentDirective,
HlmIconComponent,
HlmButtonDirective,
],
template: `
<brn-popover [state]="state()" (closed)="close()" sideOffset="5" closeDelay="100">
<button class="w-[200px] justify-between" id="edit-profile" variant="outline" brnPopoverTrigger hlmBtn>
{{ currentFramework() ? currentFramework().label : 'Select framework...' }}
<hlm-icon size="sm" name="radixCaretSort" />
</button>
<brn-cmd *brnPopoverContent="let ctx" hlmPopoverContent hlm class="p-0 w-[200px]">
<hlm-cmd-input-wrapper>
<hlm-icon name="radixMagnifyingGlass" />
<input placeholder="Search framework..." brnCmdInput hlm />
</hlm-cmd-input-wrapper>
<div *brnCmdEmpty hlmCmdEmpty>No results found.</div>
<brn-cmd-list hlm>
<brn-cmd-group hlm>
<button
*ngFor="let framework of frameworks"
brnCmdItem
[value]="framework.value"
(selected)="commandSelected(framework)"
hlm
>
<hlm-icon
[class.opacity-0]="currentFramework()?.value !== framework.value"
name="radixCheck"
hlmCmdIcon
/>
{{ framework.label }}
</button>
</brn-cmd-group>
</brn-cmd-list>
</brn-cmd>
</brn-popover>
`,
})
class ComboboxComponent {
public frameworks = [
{
label: 'AnalogJs',
value: 'analogjs',
},
{
label: 'Angular',
value: 'angular',
},
{
label: 'Vue',
value: 'vue',
},
{
label: 'Nuxt',
value: 'nuxt',
},
{
label: 'React',
value: 'react',
},
{
label: 'NextJs',
value: 'nextjs',
},
];
public currentFramework = signal<Framework | undefined>(undefined);
public state = signal<'closed' | 'open'>('closed');
close() {
this.state.set('closed');
}
commandSelected(framework: Framework) {
this.state.set('closed');
if (this.currentFramework()?.value === framework.value) {
this.currentFramework.set(undefined);
} else {
this.currentFramework.set(framework);
}
}
}
This example uses a local signal, but that is not necessary. The signal (or an BehaviorSubject) could also live in an injectable service, which allows you to open the dialog from other places
from spartan.
@tutkli let me know if my explanation helps in the meantime or if you'd like me to create a more elaborate example!
from spartan.
@goetzrobin Thank you for the example, I think is a good workaround.
I think the service should create a cdk-dialog wrapper with the contents of the component we send as an argument. Similar to how Angular cdk does. So if this is the component I want to open in a dialog:
@Component({
selector: 'app-my-dialog',
standalone: true,
template: `
<p>Hello World</p>`
})
export class MyDialogComponent{}
brnDialog.open()
should create:
<cdk-dialog-container>
<app-my-dialog>
<p>Hello World</p>
</app-my-dialog>
</brn-dialog>
I hope this makes sense.
from spartan.
Related Issues (20)
- SSR error on select component 'window' not found HOT 6
- Displaying the Icon component - adding route and view to spartan-side-nav-links HOT 8
- Adding icon as a choice in issue and PR templates
- RFC: Components overview HOT 7
- Why isn't the initial value applied to the select component after cloning the repo and running Storybook? HOT 3
- Easier usage of tooltip HOT 7
- Add the ability to group buttons HOT 1
- The select control become dirty on multiple mode with initlal value or patch value HOT 9
- Feature - making the image in The 300 clickable along with the text HOT 6
- Feature Request: "Select All" Option for Spartan-NG Select Control HOT 6
- not able to generate code (either using angular api or nx) for sonner HOT 4
- select: initial value is not set when number, initial value of multiple is erased if additional values are selected
- Include authentication UI example at examples page HOT 2
- Docs mention @ngneat/cmdk instead of @ngxpert/cmdk HOT 1
- RFC: Advanced pagination
- RFC: Radio Groups as card layouts HOT 6
- Docs: API reference for all components
- Renaming the generated `hlm-` selector to anything else breaks the `select` component HOT 10
- Popover overflowing past screen when trigger is on the edge of the screen HOT 3
- Add the multi select component
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spartan.