Skip to content

Instantly share code, notes, and snippets.

@iammerrick
Last active May 30, 2023 20:05
Show Gist options
  • Save iammerrick/44df36cafa8effca3d2209e5b0c39f49 to your computer and use it in GitHub Desktop.
Save iammerrick/44df36cafa8effca3d2209e5b0c39f49 to your computer and use it in GitHub Desktop.

CSS Component

.MyComponent {
  @component children;
  background-color: #000;
  
  .icon {
    background: #FF0000;
    @component icon;
  }
}

Supports Multiple Rendering Targets

React

import React from 'react';

const MyComponent = ({icon, children}) => (
  <div>
    <style>
    .axy {
      background-color: #000;
    }

    .zjy {
      background-color: #FF0000;
    }
    </style>
    <div className='axy'>
      {children}
      <div class='zjy'>
        {icon}
      </div>
    </div>
  </div>
);

export default MyComponent;

Angular 2

import { Component } from '@angular/core';
@Component({
  selector: 'MyComponent',
  template: '
  <div>
    <style>
    .axy {
      background-color: #000;
    }

    .zjy {
      background-color: #FF0000;
    }
    </style>
    <div className='axy'>
      <ng-content></ng-content>
      <div class='zjy'>
        <ng-content select="icon"></ng-content>
      </div>
    </div>
  </div>
'
})
export class AppComponent { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment