Giter Club home page Giter Club logo

Comments (3)

goetzrobin avatar goetzrobin commented on May 27, 2024

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.

goetzrobin avatar goetzrobin commented on May 27, 2024

@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.

tutkli avatar tutkli commented on May 27, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.