1.0.0 • Published 4 years ago

@jswork/react-details v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

react-details

Details for react.

version license size download

installation

npm install -S @jswork/react-details

properties

NameTypeRequiredDefaultDescription
classNamestringfalse-The extended className for component.
valueboolfalse-The changed value.
onChangefuncfalsenoopThe change handler.
summaryanyfalse-The summary content.
disabledboolfalse-When present, it specifies that the details should be disabled.
arrowboolfalsetrueWhen present, it specifies that the summary arrow should be display.

usage

  1. import css

    @import "~@jswork/react-details/dist/style.css";
    
    // or use sass
    @import "~@jswork/react-details/dist/style.scss";
    
    // customize your styles:
    $react-details-options: ()
  2. import js

    import ReactDemokit from '@jswork/react-demokit';
    import React from 'react';
    import ReactDOM from 'react-dom';
    import ReactDetails from '@jswork/react-details';
    import './assets/style.scss';
    
    class App extends React.Component {
      state = { value: true };
    
      render() {
        return (
          <ReactDemokit
            className="p-3 app-container"
            url="https://github.com/afeiship/react-details">
            <p className="p-3 bg-gray-200 mb-2">value: {this.state.value + ''}</p>
            <ReactDetails
              value={true}
              arrow={false}
              summary="道可道,非常道"
              onChange={(e) => {
                this.setState({ value: e.target.value });
              }}>
              道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。
              故常无欲,以观其妙,常有欲,以观其徼。
              此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。
            </ReactDetails>
          </ReactDemokit>
        );
      }
    }
    
    ReactDOM.render(<App />, document.getElementById('app'));

animation

/* remove arrow */
&::-webkit-details-marker {
  // display: none;
}


/* add animation */
&[open] summary ~ * {
  animation: open 0.5s ease-in-out;
}

@keyframes open {
  0% {
    opacity: 0;
    margin-left: -5px;
  }
  100% {
    opacity: 1;
    margin-left: 0px;
  }
}

documentation

license

Code released under the MIT license.