77
88import React , { useState } from 'react' ;
99import ReactDOM from 'react-dom' ;
10- import { action } from '@storybook/addon-actions' ;
1110import Modal from './Modal' ;
1211import Button from '../Button' ;
1312import Select from '../Select' ;
@@ -17,70 +16,6 @@ import SelectItem from '../SelectItem';
1716import TextInput from '../TextInput' ;
1817import mdx from './Modal.mdx' ;
1918
20- const buttons = {
21- 'None (0)' : '0' ,
22- 'One (1)' : '1' ,
23- 'Two (2)' : '2' ,
24- 'Three (3)' : '3' ,
25- } ;
26-
27- const props = {
28- modal : ( ) => ( {
29- numberOfButtons : ( 'Number of Buttons' , buttons , '2' ) ,
30- className : 'some-class' ,
31- open : true ,
32- danger : false ,
33- alert : false ,
34- shouldSubmitOnEnter : false ,
35- hasScrollingContent : false ,
36- hasForm : false ,
37- modalHeading : 'Modal heading' ,
38- modalLabel : 'Label' ,
39- modalAriaLabel :
40- 'A label to be read by screen readers on the modal root node' ,
41- selectorPrimaryFocus : '[data-modal-primary-focus]' ,
42- size : 'md' ,
43- onBlur : action ( 'onBlur' ) ,
44- onClick : action ( 'onClick' ) ,
45- onFocus : action ( 'onFocus' ) ,
46- onRequestClose : action ( 'onRequestClose' ) ,
47- onRequestSubmit : action ( 'onRequestSubmit' ) ,
48- onSecondarySubmit : action ( 'onSecondarySubmit' ) ,
49- preventCloseOnClickOutside : true ,
50- primaryButtonDisabled : false ,
51- primaryButtonText : 'Primary button' ,
52- } ) ,
53- modalFooter : ( numberOfButtons ) => {
54- const secondaryButtons = ( ) => {
55- switch ( numberOfButtons ) {
56- case '2' :
57- return {
58- secondaryButtonText : 'Secondary button' ,
59- } ;
60- case '3' :
61- return {
62- secondaryButtons : [
63- {
64- buttonText : 'Keep both' ,
65- onClick : action ( 'onClick' ) ,
66- } ,
67- {
68- buttonText : 'Rename' ,
69- onClick : action ( 'onClick' ) ,
70- } ,
71- ] ,
72- } ;
73- default :
74- return null ;
75- }
76- } ;
77- return {
78- passiveModal : false || numberOfButtons === '0' ,
79- ...secondaryButtons ( ) ,
80- } ;
81- } ,
82- } ;
83-
8419export default {
8520 title : 'Components/Modal' ,
8621 component : Modal ,
@@ -157,18 +92,15 @@ export const DangerModal = () => {
15792 ) ;
15893} ;
15994
160- export const Playground = ( ) => {
161- const { size, numberOfButtons, hasScrollingContent, ...modalProps } =
162- props . modal ( ) ;
163- const { passiveModal, ...footerProps } = props . modalFooter ( numberOfButtons ) ;
95+ export const Playground = ( args ) => {
16496 return (
16597 < Modal
166- passiveModal = { numberOfButtons === '0' || passiveModal }
167- size = { size || undefined }
168- hasScrollingContent = { hasScrollingContent }
169- aria-label = { hasScrollingContent ? 'Modal content' : undefined }
170- { ... modalProps }
171- { ...footerProps } >
98+ open
99+ modalHeading = "Add a custom domain"
100+ primaryButtonText = "Add"
101+ secondaryButtonText = "Cancel"
102+ aria-label = "Modal content"
103+ { ...args } >
172104 < p style = { { marginBottom : '1rem' } } >
173105 Custom domains direct requests for your apps in this Cloud Foundry
174106 organization to a URL that you own. A custom domain can be a shared
@@ -185,8 +117,7 @@ export const Playground = () => {
185117 < SelectItem value = "us-south" text = "US South" />
186118 < SelectItem value = "us-east" text = "US East" />
187119 </ Select >
188- < br />
189- { hasScrollingContent && (
120+ { args . hasScrollingContent && (
190121 < >
191122 < p >
192123 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean id
@@ -244,6 +175,63 @@ export const Playground = () => {
244175 ) ;
245176} ;
246177
178+ Playground . argTypes = {
179+ children : {
180+ table : {
181+ disable : true ,
182+ } ,
183+ } ,
184+ className : {
185+ table : {
186+ disable : true ,
187+ } ,
188+ } ,
189+ id : {
190+ table : {
191+ disable : true ,
192+ } ,
193+ } ,
194+ modalHeading : {
195+ control : 'text' ,
196+ } ,
197+ modalLabel : {
198+ control : 'text' ,
199+ } ,
200+ onKeyDown : {
201+ action : 'clicked' ,
202+ } ,
203+ onRequestClose : {
204+ action : 'clicked' ,
205+ } ,
206+ onRequestSubmit : {
207+ action : 'clicked' ,
208+ } ,
209+ onSecondarySubmit : {
210+ action : 'clicked' ,
211+ } ,
212+ primaryButtonText : {
213+ control : 'text' ,
214+ } ,
215+ secondaryButtons : {
216+ table : {
217+ disable : true ,
218+ } ,
219+ } ,
220+ secondaryButtonText : {
221+ control : 'text' ,
222+ } ,
223+ selectorPrimaryFocus : {
224+ table : {
225+ disable : true ,
226+ } ,
227+ } ,
228+ selectorsFloatingMenus : {
229+ table : {
230+ disable : true ,
231+ } ,
232+ } ,
233+ } ;
234+
247235export const WithStateManager = ( ) => {
248236 /**
249237 * Simple state manager for modals.
0 commit comments