Best JavaScript code snippet using storybook-root
index.js
Source:index.js
1import 'moment/locale/en-ca';2import '../../public/css/app.css';3import React from 'react';4import moment from 'moment';5import PropTypes from 'prop-types';6import BigCalendar from 'react-big-calendar';7import { storiesOf, linkTo } from '@kadira/storybook';8import { WithNotes } from '@kadira/storybook-addon-notes';9import { DateRangePicker } from 'react-dates';10import { START_DATE } from 'react-dates/constants';11import PeopleView from '../views/Manager/People';12import EmployeeSingleView from '../views/Manager/People/EmployeeSingle';13import GroupSingleView from '../views/Manager/People/GroupSingle';14import ScheduleView from '../views/Manager/Schedule';15import OpportunitySingleView from '../views/Manager/Schedule/OpportunitySingle';16import TimesheetView from '../views/Manager/Timesheet';17import DashboardView from '../views/Employee/Dashboard';18import NewsfeedView from '../views/Employee/Newsfeed';19import EmployeeOpportunitySingleView from '../views/Employee/Schedule/OpportunitySingle';20import EmployeeProfileView from '../views/Employee/EmployeeProfile';21import ProfileSetup from '../views/Employee/ProfileSetup';22import MainMenu from '../components/Global/MainMenu';23import SecondaryMenu from '../components/Global/SecondaryMenu';24import Box from '../components/Global/Box';25import BasicButton from '../components/Buttons/BasicButton';26import RadioButton from '../components/Buttons/RadioButton';27import ButtonBar from '../components/Buttons/ButtonBar';28import Post from '../components/Newsfeed/Post';29import PostList from '../components/Newsfeed/PostList';30import FilterContainer from '../components/Filters/FilterContainer';31import OverviewCalendar from '../components/Scheduling/OverviewCalendar';32import OpportunityModal from '../components/Scheduling/OpportunityModal';33import ShiftManager from '../components/Scheduling/ShiftManager';34import ShiftList from '../components/Scheduling/ShiftList';35import UserTable from '../components/Employees/UserTable';36import EmployeeSelectionInterface from '../components/Employees/EmployeeSelectionInterface';37import SelectIndividuals from '../components/Employees/EmployeeSelection/SelectEmployees/Individuals';38import SelectGroups from '../components/Employees/EmployeeSelection/SelectEmployees/Groups';39import SelectCustomRules from '../components/Employees/EmployeeSelection/SelectEmployees/CustomRules';40import GroupCard from '../components/Employees/Groups/Card';41import GroupCardList from '../components/Employees/Groups/CardList';42import GroupDetailsEditor from '../components/Employees/Groups/DetailsEditor';43import AvailabilityEditor from '../components/Profile/AvailabilityEditor';44import AvailabilityViewer from '../components/Profile/AvailabilityViewer';45import TimeOffRequestRequester from '../components/Profile/TimeOffRequests/Requester';46import TimeOffRequestReviewer from '../components/Profile/TimeOffRequests/Reviewer';47import NewTimeOffRequestModal from '../components/Profile/TimeOffRequests/Modal';48// import SectionSwitcher from '../components/Miscellaneous/SectionSwitcher';49const samplePeople = require('../data/people.json')50const samplePosts = require('../data/posts.json')51const sampleEvents = require('../data/opportunities.json')52const sampleTimeOffRequests = require('../data/timeOffRequests.json')53BigCalendar.setLocalizer(54 BigCalendar.momentLocalizer(moment)55);56storiesOf('Overview', module)57 .add('Welcome', () => (58 <div className="ma4 ">59 <h1>Welcome!</h1>60 <p className="measure-narrow f4">This is the pattern library for the SpotHire application. It contains the separate61 blocks used to build the interface, and examples of them in action.</p>62 <p className="measure">The components are loosely categorized according to their function or where theyâre used. Some63 components include notes in the bottom panel for usage instructions or to talk about what still needs doing.</p>64 <p className="measure">Unless you really want to dig into the nitty-gritty of each part of the app, the most65 interesting place to look will be the <code className="bg-light-gray pa1 br1 f6">Views</code> category, the66 second item in the menu on the left. There Iâve put together previews of how the components will sit together67 to build certain pages from our Information Architecture. To go for full immersion, press <code className="bg-light-gray pa1 br1 f6">Ctrl-Shift-F</code>,68 then enter as a <a className="red hover-no-underline" onClick={linkTo('Views (manager)', 'Newsfeed')} href="#manager">manager</a> or <a className="red hover-no-underline" onClick={linkTo('Views (employee)', 'Dashboard')} href="#employee">employee</a>.</p>69 <p className="measure">When looking through, keep in mind that things are still early stage. Quite a bit has70 yet to be completed, and what is posted here is still in progress. That said, there are a few questions for71 you to consider as you look through:</p>72 <ul>73 <li>Is the interface natural? Would an admin or employee be able to find their way around?</li>74 <li>Are any aspects of the interface confusing? How so?</li>75 <li>What does a more polished version of this look like?</li>76 <li>Does anything seem out of place or unnecessary?</li>77 </ul>78 <p className="measure">Thanks, and I look forward to talking more!</p>79 </div>80 ));81class MockApp extends React.Component {82 render() {83 return (84 <div>85 <MainMenu selectedItem={this.props.selectedMenuItem} userType={this.props.userType}/>86 {this.props.viewComponent}87 </div>88 );89 }90}91MockApp.propTypes = {92 selectedMenuItem: PropTypes.string.isRequired,93 viewComponent: PropTypes.element.isRequired,94 userType: PropTypes.oneOf(['manager', 'employee']).isRequired,95};96storiesOf('Views (manager)', module)97 .add('Newsfeed', () => (98 <MockApp99 selectedMenuItem="Newsfeed"100 userType="manager"101 viewComponent={102 <NewsfeedView103 posts={samplePosts}104 />105 }106 />107 ))108 .add('People', () => (109 <MockApp110 selectedMenuItem="People"111 userType="manager"112 viewComponent={113 <PeopleView114 employees={samplePeople}115 />116 }117 />118 ))119 .add('People:EmployeeSingleView', () => (120 <MockApp121 selectedMenuItem="People"122 userType="manager"123 viewComponent={124 <EmployeeSingleView125 employee={samplePeople[1]}126 />127 }128 />129 ))130 .add('People:GroupSingleView', () => (131 <MockApp132 selectedMenuItem="People"133 userType="manager"134 viewComponent={135 <GroupSingleView136 group={{137 id: 0,138 name: 'Sample Group',139 employees: samplePeople,140 type: 'static'141 }}142 />143 }144 />145 ))146 .add('Schedule', () => (147 <MockApp148 selectedMenuItem="Schedule"149 userType="manager"150 viewComponent={151 <ScheduleView152 events={sampleEvents}153 />154 }155 />156 ))157 .add('Schedule:OpportunitySingle', () => (158 <MockApp159 selectedMenuItem="Schedule"160 userType="manager"161 viewComponent={162 <OpportunitySingleView163 opportunity={sampleEvents[0]}164 />165 }166 />167 ))168 .add('Timesheet', () => (169 <MockApp170 selectedMenuItem="Timesheet"171 userType="manager"172 viewComponent={173 <TimesheetView174 employees={samplePeople}175 />176 }177 />178 ))179 .add('EmployeeProfileView', () => (180 <MockApp181 selectedMenuItem=""182 userType="manager"183 viewComponent={184 <EmployeeProfileView185 employee={samplePeople[1]}186 />187 }188 />189 ));190storiesOf('Views (employee)', module)191 .add('Dashboard', () => (192 <MockApp193 selectedMenuItem="Dashboard"194 userType="employee"195 viewComponent={196 <DashboardView197 employee={samplePeople[0]}198 events={sampleEvents.filter((event) => event.userId === 0)}199 />200 }201 />202 ))203 .add('Newsfeed', () => (204 <MockApp205 selectedMenuItem="Newsfeed"206 userType="employee"207 viewComponent={208 <NewsfeedView209 posts={samplePosts}210 />211 }212 />213 ))214 .add('Schedule', () => (215 <MockApp216 selectedMenuItem="Schedule"217 userType="employee"218 viewComponent={219 <ScheduleView220 events={sampleEvents}221 />222 }223 />224 ))225 .add('Schedule:OpportunitySingle', () => (226 <MockApp227 selectedMenuItem="Schedule"228 userType="employee"229 viewComponent={230 <EmployeeOpportunitySingleView231 opportunity={sampleEvents[0]}232 />233 }234 />235 ))236 .add('Schedule:OpportunitySingle (not all day)', () => (237 <MockApp238 selectedMenuItem="Schedule"239 userType="employee"240 viewComponent={241 <EmployeeOpportunitySingleView242 opportunity={sampleEvents[1]}243 />244 }245 />246 ))247 .add('EmployeeProfileView', () => (248 <MockApp249 selectedMenuItem=""250 userType="employee"251 viewComponent={252 <EmployeeProfileView253 employee={samplePeople[1]}254 />255 }256 />257 ))258 .add('ProfileSetup', () => (259 <ProfileSetup employee={samplePeople[3]}/>260 ));261storiesOf('Global', module)262 .add('MainMenu', () => (263 <WithNotes>264 <MainMenu/>265 </WithNotes>266 ))267 .add('SecondaryMenu', () => (268 <WithNotes>269 <SecondaryMenu270 items={[271 {272 text: 'Item 1',273 href: '#item1'274 },275 {276 text: 'Item 2',277 href: '#item2'278 },279 {280 text: 'Item 3',281 href: '#item3'282 }283 ]}284 />285 </WithNotes>286 ))287 .add('Box without title', () => (288 <WithNotes>289 <div className="ma4">290 <Box>291 <p>Some test content in the Box.</p>292 </Box>293 </div>294 </WithNotes>295 ))296 .add('Box with block title', () => (297 <WithNotes>298 <div className="ma4">299 <Box title="Box title">300 <p>Some test content in the Box.</p>301 </Box>302 </div>303 </WithNotes>304 ))305 .add('Box with inline title', () => (306 <WithNotes>307 <div className="ma4">308 <Box title="Box title" headingType="inline">309 <p>Some test content in the Box.</p>310 </Box>311 </div>312 </WithNotes>313 ));314storiesOf('Content', module)315 .add('Paragraph', () => (316 <WithNotes>317 <div className="ma4 ">318 <p>Just a paragraph. Nothing special.</p>319 <p>Put them one after the other, and they stack fine.</p>320 <p className="measure">Add the <code className="bg-light-gray pa1 br1 f6">.measure</code> class to constrain it to a reasonable width (works for any element). Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium asperiores impedit ipsam laudantium modi mollitia placeat sunt vero voluptas. Ab, accusamus ad aliquam animi asperiores aspernatur consectetur, earum fuga ipsam iste laudantium, molestias nemo neque nisi nostrum nulla numquam provident quas reiciendis rem sint sit tenetur ut. Animi eius enim ipsa ipsam molestiae.</p>321 </div>322 </WithNotes>323 ))324 .add('Paragraph:Serif', () => (325 <WithNotes>326 <div className="ma4 app-serif">327 <p>Just a paragraph, nothing special.</p>328 <p>Use the <code className="bg-light-gray pa1 br1 f6">.app-serif</code> class to set it to our serif font family stack.</p>329 <p className="measure">Add the <code className="bg-light-gray pa1 br1 f6">.measure</code> class to constrain it to a reasonable width (works for any element). Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium asperiores impedit ipsam laudantium modi mollitia placeat sunt vero voluptas. Ab, accusamus ad aliquam animi asperiores aspernatur consectetur, earum fuga ipsam iste laudantium, molestias nemo neque nisi nostrum nulla numquam provident quas reiciendis rem sint sit tenetur ut. Animi eius enim ipsa ipsam molestiae.</p>330 </div>331 </WithNotes>332 ))333 .add('Headings', () => (334 <WithNotes>335 <div className="ma4 ">336 <h1>Top-level heading</h1>337 <p>Should only ever contain the title of the page.</p>338 <h2>Middle-grade heading</h2>339 <p>Likely most common heading. Any first-class section.</p>340 <h3>Third-tier heading</h3>341 <p>If you need to divide up a first-class section.</p>342 </div>343 </WithNotes>344 ))345 .add('Lists', () => (346 <WithNotes>347 <div className="ma4 ">348 <p>Unordered:</p>349 <ul>350 <li>An item</li>351 <li>Another</li>352 <li>A final</li>353 </ul>354 <p>Ordered:</p>355 <ol>356 <li>First item</li>357 <li>Second item</li>358 <li>Third item</li>359 </ol>360 <p>With longer content:</p>361 <ol>362 <li className="measure">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dicta eligendi, facere illo incidunt odit placeat quidem quod temporibus! Laboriosam, quidem.</li>363 <li className="measure">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque cum ducimus odio perferendis voluptates voluptatibus. A dolorem error molestias nulla officia suscipit veniam. Animi architecto, assumenda culpa dolor eos non provident recusandae! Ab accusantium commodi consectetur dolorem esse et fuga id, ipsum magnam molestias obcaecati, odit quasi repudiandae tempora voluptatibus? Commodi earum ipsum iure perspiciatis quisquam? Aliquam amet beatae consectetur cumque delectus dolore dolores eaque, est explicabo, facere fugiat id illum iste libero magni, maxime molestiae nostrum omnis optio repellat similique suscipit tempora. Assumenda, autem debitis in nobis obcaecati odio placeat provident quae quidem recusandae rem sed totam ut vitae!</li>364 <li className="measure">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci at, corporis dolorem id obcaecati veritatis voluptatum? Animi aperiam commodi corporis ex explicabo fuga fugiat id magni maiores maxime molestiae, nisi quidem, tenetur. At eveniet ex ipsam iste labore maiores maxime quam quas voluptatem voluptatibus? Architecto beatae doloremque esse excepturi, facilis magnam natus nemo soluta? Asperiores debitis, dolore eius eos excepturi illum iste labore molestiae nihil porro, similique soluta, ullam voluptas. Ad obcaecati quasi soluta sunt.</li>365 </ol>366 </div>367 </WithNotes>368 ));369storiesOf('Buttons', module)370 .add('BasicButton:Standard', () => (371 <WithNotes>372 <div className="ma4">373 <BasicButton type="standard">Add Employees</BasicButton>374 </div>375 </WithNotes>376 ))377 .add('BasicButton:Neutral', () => (378 <WithNotes>379 <div className="ma4">380 <BasicButton type="neutral">Add Employees</BasicButton>381 </div>382 </WithNotes>383 ))384 .add('BasicButton:Positive', () => (385 <WithNotes>386 <div className="ma4">387 <BasicButton type="positive">Add Employees</BasicButton>388 </div>389 </WithNotes>390 ))391 .add('BasicButton:Negative', () => (392 <WithNotes>393 <div className="ma4">394 <BasicButton type="negative">Remove Employees</BasicButton>395 </div>396 </WithNotes>397 ))398 .add('IconButton:Plus', () => (399 <WithNotes>400 <div className="ma4">401 <BasicButton type="positive" className="button--with-icon button--icon-plus">Add Opportunity</BasicButton>402 </div>403 </WithNotes>404 ))405 .add('IconButton:Minus', () => (406 <WithNotes>407 <div className="ma4">408 <BasicButton type="negative" className="button--with-icon button--icon-minus">Delete Opportunity</BasicButton>409 </div>410 </WithNotes>411 ))412 .add('RadioButton:Unselected', () => (413 <WithNotes>414 <div className="ma4">415 <RadioButton>Unselected</RadioButton>416 </div>417 </WithNotes>418 ))419 .add('RadioButton:Selected', () => (420 <WithNotes>421 <div className="ma4">422 <RadioButton checked>Selected</RadioButton>423 </div>424 </WithNotes>425 ))426 .add('ButtonBar', () => (427 <WithNotes>428 <ButtonBar className="ma4">429 <RadioButton>Unselected</RadioButton>430 <RadioButton>Stuck in the middle</RadioButton>431 <RadioButton checked>Selected</RadioButton>432 </ButtonBar>433 </WithNotes>434 ));435storiesOf('Newsfeed', module)436 .add('Open Post', () => (437 <WithNotes>438 <div className="pa4 bg-near-white">439 <Post440 post={samplePosts[0]}441 isOpen={true}442 />443 </div>444 </WithNotes>445 ))446 .add('Closed Post with automatic excerpt', () => (447 <WithNotes>448 <div className="pa4 bg-near-white">449 <Post450 post={samplePosts[0]}451 isOpen={false}452 />453 </div>454 </WithNotes>455 ))456 .add('Closed Post with custom excerpt', () => (457 <WithNotes>458 <div className="pa4 bg-near-white">459 <Post460 post={{461 ...samplePosts[1]462 }}463 isOpen={false}464 />465 </div>466 </WithNotes>467 ))468 .add('PostList', () => (469 <WithNotes>470 <div className="pa4 bg-near-white">471 <PostList472 posts={samplePosts}473 />474 </div>475 </WithNotes>476 ));477storiesOf('Filters', module)478 .add('FilterContainer', () => (479 <WithNotes>480 <div className="pa4 bg-near-white mw6">481 <FilterContainer>482 <label className="db mb2 f6" htmlFor="filterDemo">Label</label>483 <input type="text" className="w-100 pa1 mt0" name="filterDemo" id="filterDemo"/>484 </FilterContainer>485 </div>486 </WithNotes>487 ));488storiesOf('Scheduling', module)489 .add('DateRangePicker', () => (490 <div className=" pa4">491 <DateRangePicker492 startDate={moment()}493 endDate={moment().add(3, 'days')}494 onDatesChange={({ startDate, endDate }) => console.log({ startDate, endDate })}495 focusedInput={START_DATE}496 onFocusChange={focusedInput => console.log({ focusedInput })}497 />498 </div>499 ))500 .add('DefaultCalendar', () => (501 <WithNotes notes="The default, full calendar.">502 <div className=" pa4" style={{height: '100vh'}}>503 <BigCalendar504 events={sampleEvents}505 startAccessor={(event) => new Date(event.dates.start)}506 endAccessor={(event) => new Date(event.dates.end)}507 />508 </div>509 </WithNotes>510 ))511 .add('OverviewCalendar', () => (512 <WithNotes notes="">513 <div className="ma4">514 <Box title="Calendar">515 <OverviewCalendar516 events={sampleEvents}517 highlightFilter={{518 property: 'userId',519 values: [0]520 }}521 />522 </Box>523 </div>524 </WithNotes>525 ))526 .add('OpportunityModal', () => (527 <WithNotes notes="">528 <OpportunityModal529 updateOpportunity={(opportunity) => console.log(opportunity)}530 closeModal={() => console.log('modal "closed"')}531 isOpen={true}532 opportunity={{533 isAllDay: false,534 dates: {535 start: new Date(1970, 0, 0),536 end: new Date(1970, 0, 0)537 },538 employees: {539 invited: 'all',540 confirmed: []541 }542 }}543 />544 </WithNotes>545 ))546 .add('ShiftManager', () => (547 <WithNotes notes="">548 <div className="pa4 min-vh-100 bg-near-white">549 <ShiftManager/>550 </div>551 </WithNotes>552 ))553 .add('ShiftList', () => (554 <WithNotes>555 <div className="pa4 bg-near-white">556 <ShiftList/>557 </div>558 </WithNotes>559 ));560storiesOf('Employees', module)561 .add('UserTable', () => (562 <WithNotes>563 <div className="pa4 bg-near-white">564 <UserTable/>565 </div>566 </WithNotes>567 ))568 .add('UserTable:Inline new user interface', () => (569 <WithNotes notes="An experimental interface to add new users inline with the table interface.">570 <div className="pa4 bg-near-white">571 <UserTable inlineAddingRowIsOpen={true}/>572 </div>573 </WithNotes>574 ))575 .add('EmployeeSelectionInterface', () => (576 <WithNotes>577 <div className="pa4 bg-white">578 <EmployeeSelectionInterface className="pa3 ba b--black-20" employees={samplePeople}/>579 </div>580 </WithNotes>581 ))582 .add('EmployeeSelectionInterface:SelectEmployees:Individuals', () => (583 <WithNotes>584 <div className="pa4 bg-white">585 <div className="w-50 pa3">586 <SelectIndividuals/>587 </div>588 </div>589 </WithNotes>590 ))591 .add('EmployeeSelectionInterface:SelectEmployees:Groups', () => (592 <WithNotes>593 <div className="pa4 bg-white">594 <div className="w-50 pa3">595 <SelectGroups/>596 </div>597 </div>598 </WithNotes>599 ))600 .add('EmployeeSelectionInterface:SelectEmployees:CustomRules', () => (601 <WithNotes>602 <div className="pa4 bg-white">603 <div className="w-50 pa3">604 <SelectCustomRules/>605 </div>606 </div>607 </WithNotes>608 ));609storiesOf('Employees:Groups', module)610 .add('Card', () => (611 <WithNotes>612 <div className="pa4 bg-near-white">613 <GroupCard614 group={{615 id: 0,616 name: 'Sample Group',617 employees: samplePeople,618 type: 'static'619 }}620 />621 </div>622 </WithNotes>623 ))624 .add('CardList', () => (625 <WithNotes>626 <div className="pa4 bg-near-white">627 <GroupCardList628 groups={[...Array(10).keys()].map((number) => {629 return {630 id: number,631 name: `Sample Group ${number + 1}`,632 employees: samplePeople,633 type: 'static'634 };635 })}636 onSelectGroup={(groupId) => console.log(`Group ID ${groupId} selected`)}637 />638 </div>639 </WithNotes>640 ))641 .add('DetailsEditor', () => (642 <WithNotes>643 <div className="pa4 bg-near-white">644 <GroupDetailsEditor645 group={{646 id: 0,647 name: 'Sample Group',648 employees: samplePeople,649 type: 'static'650 }}651 />652 </div>653 </WithNotes>654 ));655storiesOf('Profile', module)656 .add('AvailabilityEditor', () => (657 <WithNotes>658 <div className="pa4 bg-near-white">659 <Box className="w-third" title="Availability">660 <AvailabilityEditor employee={samplePeople[0]} onSubmitAvailability={(availability) => console.log(availability)}/>661 </Box>662 </div>663 </WithNotes>664 ))665 .add('AvailabilityViewer', () => (666 <WithNotes>667 <div className="pa4 bg-near-white">668 <Box className="w-third" title="Availability">669 <AvailabilityViewer employee={samplePeople[0]}/>670 </Box>671 </div>672 </WithNotes>673 ))674 .add('TimeOffRequestRequester', () => (675 <WithNotes>676 <div className="pa4 bg-near-white">677 <Box className="w-third" title="Time Off Requests">678 <TimeOffRequestRequester timeOffRequests={sampleTimeOffRequests} employee={samplePeople[3]}/>679 </Box>680 </div>681 </WithNotes>682 ))683 .add('TimeOffRequestReviewer', () => (684 <WithNotes>685 <div className="pa4 bg-near-white">686 <Box className="w-third" title="Time Off Requests">687 <TimeOffRequestReviewer timeOffRequests={sampleTimeOffRequests}/>688 </Box>689 </div>690 </WithNotes>691 ))692 .add('NewTimeOffRequestModal', () => (693 <WithNotes>694 <NewTimeOffRequestModal695 closeModal={() => console.log('modal "closed"')}696 isOpen={true}697 onSubmitRequest={(request) => console.log(request)}698 />699 </WithNotes>...
common.js
Source:common.js
1import { addDecorator } from '@storybook/react-native'2import { withKnobs } from '@storybook/addon-knobs'3import { withNotes } from '@storybook/addon-ondevice-notes'4addDecorator(withKnobs)...
Using AI Code Generation
1import { WithNotes } from 'storybook-addon-notes';2import { storiesOf } from '@storybook/react';3import { withKnobs } from '@storybook/addon-knobs';4import { withInfo } from '@storybook/addon-info';5import { withA11y } from '@storybook/addon-a11y';6const stories = storiesOf('Components', module);7stories.addDecorator(withKnobs);8stories.addDecorator(withA11y);9stories.addDecorator(withInfo);10stories.add('My Component', () => <MyComponent />, {11});12import { WithNotes } from 'storybook-addon-notes';13import { storiesOf } from '@storybook/react';14import { withKnobs } from '@storybook/addon-knobs';15import { withInfo } from '@storybook/addon-info';16import { withA11y } from '@storybook/addon-a11y';17const stories = storiesOf('Components', module);18stories.addDecorator(withKnobs);19stories.addDecorator(withA11y);20stories.addDecorator(withInfo);21stories.add('My Component', () => <MyComponent />, {22});
Using AI Code Generation
1import { WithNotes } from 'storybook-addon-notes';2import { storiesOf } from '@storybook/react';3import { withKnobs, text } from '@storybook/addon-knobs';4import { withNotes } from '@storybook/addon-notes';5import React from 'react';6import { Button } from '@storybook/react/demo';7storiesOf('Button', module)8 .addDecorator(withKnobs)9 .add('with text', () => <Button>{text('Label', 'Hello Button')}</Button>)10 .add('with some emoji', () => <Button>😀 😎 👍 💯</Button>)11 .add(12 withNotes('A very simple button')(() => (13 <Button onClick={action('clicked')}>Hello Button</Button>14 .add(15 withNotes('A very simple button')(() => (16 <Button onClick={action('clicked')}>{text('Label', 'Hello Button')}</Button>17 .add(18 withNotes('A very simple button')(() => (19 <Button onClick={action('clicked')}>{text('Label', 'Hello Button')}</Button>20 );21import React from 'react';22import { shallow } from 'enzyme';23import { Button } from '@storybook/react/demo';24import { testStory } from 'storybook-addon-test';25testStory('Button', 'with notes and knobs and a component', () => {26 const wrapper = shallow(<Button>Hello Button</Button>);27 expect(wrapper).toMatchSnapshot();28});29import React from 'react';30import { shallow } from 'enzyme';31import { Button } from '@storybook/react/demo';32import { testStory } from 'storybook-addon-test';33testStory('Button', 'with notes', () => {34 const wrapper = shallow(<Button>Hello Button</Button>);35 expect(wrapper).toMatchSnapshot();36});37import React from 'react';38import { shallow } from 'enzyme';39import { Button } from '@storybook/react/demo';40import { testStory } from 'storybook-addon-test';41testStory('Button', 'with text', () => {42 const wrapper = shallow(<Button>Hello Button</Button>);
Using AI Code Generation
1import React from 'react';2import { storiesOf } from '@storybook/react';3import { WithNotes } from 'storybook-addon-notes';4storiesOf('Addons|Notes', module)5 .addDecorator(story => <WithNotes notes="My notes">{story()}</WithNotes>)6 .add('with text', () => <button>Hello Button</button>);7import React from 'react';8import { storiesOf } from '@storybook/react';9import { WithNotes } from '@storybook/addon-notes';10storiesOf('Addons|Notes', module)11 .addDecorator(story => <WithNotes notes="My notes">{story()}</WithNotes>)12 .add('with text', () => <button>Hello Button</button>);
Using AI Code Generation
1import { WithNotes } from 'storybook-root';2storiesOf('Item', module)3 .add('with text', WithNotes('some notes')( () => (4 )));5import { WithNotes } from 'storybook-root';6describe('Item', () => {7 it('should render with text', () => {8 const story = WithNotes('some notes')( () => (9 ));10 const wrapper = mount(story);11 expect(wrapper.find('Item')).to.have.length(1);12 });13});14 ✓ should render with text (4ms)15 1 test passed (5ms)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!