Skip to content

Support styling components from outside with style hooks #10663

Closed

Description

@aegyed91

I'm submitting a feature request:

In Shadow DOM you can create style hooks using CSS custom properties. It is possible in polymer too with custom-css-mixins.

Angular should support style hooks / or style projections.

Here is the syntax:

@Component({
  selector: 'ns-button',
  template: `
    <button>
      <i class="icon fa fa-fw fa-star"></i>
      <ng-content></ng-content>
    </button>
  `,
  styles: [`
    :host { 
      display: inline-block;

      /* projects --ns-button styles, this is like <ng-content></ng-content> 
        on the template level */
      @apply(--ns-button);
    }
    .icon {
      height: auto;
      max-width: 35px;
      @apply(--ns-button-icon)
    }
  `]
})
class NsButton {
}

@Component({
  selector: 'ns-app',
  template: `<ns-button>Click me!</ns-button>`,
  styles: [`
    ns-button {
      /* this is how you feed it with input, this is like ContentChild
       on the template level */
      --ns-button: {
        background-color: green;
        border-radius: 4px;
        border: 1px solid gray;
      };
      --ns-button-icon: {
        color: green;
      };
    }
  `]
})
class NsApp {
}

@pkozlowski-opensource @Foxandxss

Activity

  1. aegyed91 commented on Aug 11, 2016

    @aegyed91
    Author

    You can even use polymer components in angular2 and use polymer's css-mixins projection.

    import { PolymerElement } from '@vaadin/angular2-polymer';
    
    @Component({
      selector: 'ns-app',
      directives: [
        PolymerElement('app-drawer'),
        PolymerElement('app-header'),
        PolymerElement('app-toolbar'),
        PolymerElement('paper-icon-button'),
        ],
      template: `
        <app-drawer [opened]="true" [swipeOpen]="true" #drawer>
          <div style="height: 80px"></div>
          <h3>side menu</h3>
          <ul>
            <li><a href="#">Home</a></li>
          </ul>
        </app-drawer>
    
        <app-header reveals>
          <app-toolbar>
            <paper-icon-button icon="menu" (click)="drawer.toggle()"></paper-icon-button>
            <div main-title>brand</div>
            <paper-icon-button icon="search"></paper-icon-button>
          </app-toolbar>
        </app-header>
    
        <div>
          <h3>main container</h3>
        </div>    
      `,
      styles: [require('./app.component.scss'), `    
        app-toolbar {
          /* you are projecting styles here */
          --app-toolbar-font-size: 20px;
        }
      `]
    })
    export class NsApp {
    }
  2. changed the title [-]Support styling component from outside with style hooks[/-] [+]Support styling components from outside with style hooks[/+] on Aug 11, 2016
  3. zoechi commented on Aug 18, 2016

    @zoechi
    Contributor

    Sounds like #2567, #6274

  4. added this to the Backlog milestone on Jan 23, 2018
  5. splincode commented on Jul 25, 2018

    @splincode
    Contributor

    @tsm91 Is the issue relevant? Maybe close the task...

  6. angular-robot commented on Jun 4, 2021

    @angular-robot
    Contributor

    Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

    Find more details about Angular's feature request process in our documentation.

  7. angular-robot commented on Jun 24, 2021

    @angular-robot
    Contributor

    Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

    We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

    You can find more details about the feature request process in our documentation.

  8. angular-automatic-lock-bot commented on Mar 4, 2022

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  9. locked and limited conversation to collaborators on Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimecore: stylesheetsfeatureLabel used to distinguish feature request from other issuesfreq2: medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions