Git Product home page Git Product logo

disbook's Issues

dicey action

Screenshot from 2020-05-26 15-55-09
I forked the Button story and customized the action..
so next I customize the Button to make a dice. I expected it to still show the same action as before.. but now it shows none. I was going to work on learning how to make the action panel to show it calling a random function or what it rolled.. but I'm more confused why it's showing nothing. Is there a way I should be importing the function into StoryBook.. or since they are both called on click they could be conflicting to show nothing?
Screenshot from 2020-05-26 15-55-54

MyDice.js

// import React from 'react';
// // import PropTypes from 'prop-types';
// const MyDice = ({ onClick }) => (
//   <button onClick={onClick}>dis My Dice</button>
// );

// export default MyDice; 

import React from 'react';

// const MyDice = ({ onClick }) => (

class MyDice extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      value: 7,
    };
  }

  generateRandom(min, max) {
    return Math.floor(Math.random() * (max - min + 1) + min);
  }

  render() {
    return (
      <button
        className="myDice"
        onClick={
          () => this.setState(
            { value: this.generateRandom(1, 6) }
          )
        }>
        {this.state.value}
      </button>
    );
  }
}

export default MyDice;

MyDice.stories.js

import React from 'react';
import MyDice from '../MyDice/MyDice';
import imageUrl from '../../shared/images/logo.svg';
import { action } from '@storybook/addon-actions';

export default {
  title: 'MyDice',
  component: MyDice,
  parameters: {
    assets: [
      imageUrl, // link to a file imported
      'https://via.placeholder.com/300/09f/fff.png', // link to an external image
      'https://www.example.com', // link to a webpage
      'https://www.example.com?id={id}', // link to a webpage with the current story's id in the url
    ],
  },
};

export const Text = () => <MyDice onClick={action('dis clicked My Text Dice')}>Hello MyDice</MyDice>;

export const Emoji = () => (
  <MyDice onClick={action('dis clicked.. but no emojis, so sad face')}>
    <span role="img" aria-label="so cool">
      ๐Ÿ˜€ ๐Ÿ˜Ž ๐Ÿ‘ ๐Ÿ’ฏ
    </span>
  </MyDice>
);

https://turtlewolf.github.io/disBook/?path=/story/mydice--text

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.