0.3.12 • Published 2 years ago

mediumtutorial v0.3.12

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

StencilJS-React-practice-medium

AboutTechnologies Used
StepsLinks

About

This repo is used as a scrap repo to test all major infrastucural changes that will be made to SPEC-ods.

Return to top

1.1- mkdir <projectname>
1.2- cd <projectname>

2.1- Run npm init stencil
2.2- Choose the component option
2.3- Name your project
2.4- Run npm install

mkdir src/components/my-accordion
touch src/components/my-accordion/my-accordion.tsx
import { Component, State, EventEmitter, Event, Prop, h } from '@stencil/core';

@Component({
  tag: 'my-accordion',
  styleUrl: 'my-accordion.scss',
  shadow: true
})

export class MyComponent {

  @State() toggle: boolean = false;

  @Event() onToggle: EventEmitter;

  @Prop() label: string;

  @Prop() description: string;

  @Prop() width: string;

  @Prop() color: string;

  toggleComponent() {
    this.toggle = !this.toggle;
    this.onToggle.emit({ visible: this.toggle });
  }

  render() {

    return (
      <div>
      <button class="accordion"
      style={{
        width: this.width,
        backgroundColor: this.color,
      }}
      onClick={() => this.toggleComponent()}>
      {this.label}
      {this.toggle ? <span>&#9650;</span> : <span>&#9660;</span>}
      </button>
      <div class={`content-box ${this.toggle ? 'open' : 'close'}`}
      style={{width: this.width}}>
      <p>{this.description}</p>
      </div>
      </div>
    )
  }
}
touch src/components/my-accordion/my-accordion.scss
* {
    font-family: 'Lato', sans-serif;
}

.container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center
}

.accordion {
    cursor: pointer;
    padding: 18px;
    text-align: left;
    border-radius: 20px;
    font-size: 1.2rem;
    font-weight: bold;
    outline: 0;
    span {
        float: right;
    }
}
 
 .open {
    display: block;
    height: auto;
    border-radius: 20px;
    border: 0.5px solid rgb(199, 197, 197);
    width: 200px;
 }

 p {
    padding: 18px;
 }

 .close {
    display: none;
 }
<body>
  <my-accordion width='100%' 
                label='Bacon Ipsum'
                color='pink'
                description="Bacon ipsum dolor amet pork chop sausage turkey spare ribs ham hock cupim pork loin capicola bacon ham filet mignon prosciutto boudin turducken. Shank corned beef burgdoggen jowl ribeye. Ham pork pastrami rump meatball buffalo venison andouille picanha fatback pork loin. Venison doner porchetta, chicken leberkas fatback burgdoggen ham andouille landjaeger alcatra. Pork belly pork jerky prosciutto leberkas tail salami tongue frankfurter turducken short loin flank."></my-accordion>
  <my-accordion width='100%'
                label='Cat Ipsum'
                color='aquamarine'
                description="Human give me attention meow i want to go outside let me go outside nevermind inside is better but cats are cute flex claws on the human's belly and purr like a lawnmower find something else more interesting, yet lick sellotape lick butt and make a weird face. The cat was chasing the mouse lick the plastic bag for furrier and even more furrier hairball but scratch at door to be let outside, get let out then scratch at door immmediately after to be let back in. "></my-accordion>
  <my-accordion width='100%'
                color='#eee'
                description="I feel empty."></my-accordion>
</body>
npm start
npm run build
npm publish

The completion of this app can be found here

npx create-react-app appname
npm install
npm install mediumtutorial --save
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

import { applyPolyfills, defineCustomElements } from 'spec-/loader';
// ^^^!!!This part is the magic import!!!^^^

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();

applyPolyfills().then(() => {
  defineCustomElements(window);
});
// ^^^!!!This part is the magic export!!!^^^
import React from 'react';
import './App.css';
import 'mediumtutorial';


function App() {

  const array = [
    {
      label: 'Accordion 1',
      description: 'Lorem ipsum',
      color: '#439ECA',
      width: '300px'
    },
    {
      label: 'Accordion 2',
      description: 'Lorem ipsum',
      color: '#7EC74A',
      width: '300px'
    },
    {
      label: 'Accordion 3',
      description: 'Lorem ipsum',
      color: '#F8CD41',
      width: '300px'
    }
  ]
  return (
    <div className="App">
      {
        array.map((array) => {
          return (
            <my-accordion 
            label={array.label}
            description={array.description}
            color={array.color}
            width={array.width}>
            </my-accordion>
          )})
      }
    </div>
  );
}

export default App;

npm start

Technologies Used

Return to top

Links

Return to top
0.3.12

2 years ago

0.1.0

2 years ago

0.3.0

2 years ago

0.0.3

2 years ago

0.2.0

2 years ago

0.0.4

2 years ago

0.0.2

3 years ago

0.0.1

3 years ago