2021-04-13 14:20:02 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react' ;
2021-05-27 15:43:39 +00:00
import { noop } from 'lodash' ;
2021-04-13 14:20:02 +00:00
import { action } from '@storybook/addon-actions' ;
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n' ;
2021-04-13 14:20:02 +00:00
import enMessages from '../../_locales/en/messages.json' ;
2021-05-27 15:43:39 +00:00
import { Button } from './Button' ;
2021-04-13 14:20:02 +00:00
import { Modal } from './Modal' ;
const i18n = setupI18n ( 'en' , enMessages ) ;
2022-06-07 00:48:02 +00:00
export default {
title : 'Components/Modal' ,
} ;
2021-04-13 14:20:02 +00:00
const onClose = action ( 'onClose' ) ;
const LOREM_IPSUM =
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.' ;
2022-06-07 00:48:02 +00:00
export const BareBonesShort = ( ) : JSX . Element = > (
2022-07-21 00:07:09 +00:00
< Modal i18n = { i18n } useFocusTrap = { false } >
Hello world !
< / Modal >
2022-06-07 00:48:02 +00:00
) ;
2021-04-13 14:20:02 +00:00
2022-06-07 00:48:02 +00:00
BareBonesShort . story = {
name : 'Bare bones, short' ,
} ;
export const BareBonesLong = ( ) : JSX . Element = > (
2022-07-21 00:07:09 +00:00
< Modal i18n = { i18n } useFocusTrap = { false } >
2021-04-13 14:20:02 +00:00
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< / Modal >
2022-06-07 00:48:02 +00:00
) ;
BareBonesLong . story = {
name : 'Bare bones, long' ,
} ;
2021-04-13 14:20:02 +00:00
2022-06-07 00:48:02 +00:00
export const BareBonesLongWithButton = ( ) : JSX . Element = > (
2021-08-02 21:19:18 +00:00
< Modal i18n = { i18n } >
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< Modal.ButtonFooter >
< Button onClick = { noop } > Okay < / Button >
< / Modal.ButtonFooter >
< / Modal >
2022-06-07 00:48:02 +00:00
) ;
BareBonesLongWithButton . story = {
name : 'Bare bones, long, with button' ,
} ;
2021-08-02 21:19:18 +00:00
2022-06-07 00:48:02 +00:00
export const TitleXButtonBodyAndButtonFooter = ( ) : JSX . Element = > (
2021-04-13 14:20:02 +00:00
< Modal i18n = { i18n } title = "Hello world" onClose = { onClose } hasXButton >
{ LOREM_IPSUM }
2021-05-27 15:43:39 +00:00
< Modal.ButtonFooter >
< Button onClick = { noop } > Okay < / Button >
< / Modal.ButtonFooter >
< / Modal >
2022-06-07 00:48:02 +00:00
) ;
2021-05-27 15:43:39 +00:00
2022-06-07 00:48:02 +00:00
TitleXButtonBodyAndButtonFooter . story = {
name : 'Title, X button, body, and button footer' ,
} ;
export const LotsOfButtonsInTheFooter = ( ) : JSX . Element = > (
2021-05-27 15:43:39 +00:00
< Modal i18n = { i18n } onClose = { onClose } >
Hello world !
< Modal.ButtonFooter >
< Button onClick = { noop } > Okay < / Button >
< Button onClick = { noop } > Okay < / Button >
< Button onClick = { noop } > Okay < / Button >
< Button onClick = { noop } >
This is a button with a fairly large amount of text
< / Button >
< Button onClick = { noop } > Okay < / Button >
< Button onClick = { noop } >
This is a button with a fairly large amount of text
< / Button >
< Button onClick = { noop } > Okay < / Button >
< / Modal.ButtonFooter >
2021-04-13 14:20:02 +00:00
< / Modal >
2022-06-07 00:48:02 +00:00
) ;
LotsOfButtonsInTheFooter . story = {
name : 'Lots of buttons in the footer' ,
} ;
2021-04-13 14:20:02 +00:00
2022-06-07 00:48:02 +00:00
export const LongBodyWithTitle = ( ) : JSX . Element = > (
2022-07-21 00:07:09 +00:00
< Modal i18n = { i18n } title = "Hello world" onClose = { onClose } useFocusTrap = { false } >
2021-04-13 14:20:02 +00:00
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< / Modal >
2022-06-07 00:48:02 +00:00
) ;
LongBodyWithTitle . story = {
name : 'Long body with title' ,
} ;
2021-04-13 14:20:02 +00:00
2022-06-07 00:48:02 +00:00
export const LongBodyWithTitleAndButton = ( ) : JSX . Element = > (
2021-08-02 21:19:18 +00:00
< Modal i18n = { i18n } title = "Hello world" onClose = { onClose } >
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< Modal.ButtonFooter >
< Button onClick = { noop } > Okay < / Button >
< / Modal.ButtonFooter >
< / Modal >
2022-06-07 00:48:02 +00:00
) ;
2021-08-02 21:19:18 +00:00
2022-06-07 00:48:02 +00:00
LongBodyWithTitleAndButton . story = {
name : 'Long body with title and button' ,
} ;
export const LongBodyWithLongTitleAndXButton = ( ) : JSX . Element = > (
2021-04-13 14:20:02 +00:00
< Modal
i18n = { i18n }
title = { LOREM_IPSUM . slice ( 0 , 104 ) }
hasXButton
onClose = { onClose }
>
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< / Modal >
2022-06-07 00:48:02 +00:00
) ;
LongBodyWithLongTitleAndXButton . story = {
name : 'Long body with long title and X button' ,
} ;
2021-08-06 00:17:05 +00:00
2022-06-07 00:48:02 +00:00
export const WithStickyButtonsLongBody = ( ) : JSX . Element = > (
2021-08-06 00:17:05 +00:00
< Modal hasStickyButtons hasXButton i18n = { i18n } onClose = { onClose } >
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< p > { LOREM_IPSUM } < / p >
< Modal.ButtonFooter >
< Button onClick = { noop } > Okay < / Button >
< Button onClick = { noop } > Okay < / Button >
< / Modal.ButtonFooter >
< / Modal >
2022-06-07 00:48:02 +00:00
) ;
WithStickyButtonsLongBody . story = {
name : 'With sticky buttons long body' ,
} ;
2021-08-06 00:17:05 +00:00
2022-06-07 00:48:02 +00:00
export const WithStickyButtonsShortBody = ( ) : JSX . Element = > (
2021-08-06 00:17:05 +00:00
< Modal hasStickyButtons hasXButton i18n = { i18n } onClose = { onClose } >
< p > { LOREM_IPSUM . slice ( 0 , 140 ) } < / p >
< Modal.ButtonFooter >
< Button onClick = { noop } > Okay < / Button >
< Button onClick = { noop } > Okay < / Button >
< / Modal.ButtonFooter >
< / Modal >
2022-06-07 00:48:02 +00:00
) ;
2021-08-06 00:17:05 +00:00
2022-06-07 00:48:02 +00:00
WithStickyButtonsShortBody . story = {
name : 'With sticky buttons short body' ,
} ;
export const StickyFooterLotsOfButtons = ( ) : JSX . Element = > (
2021-08-06 00:17:05 +00:00
< Modal hasStickyButtons i18n = { i18n } onClose = { onClose } title = "OK" >
< p > { LOREM_IPSUM } < / p >
< Modal.ButtonFooter >
< Button onClick = { noop } > Okay < / Button >
< Button onClick = { noop } > Okay < / Button >
< Button onClick = { noop } > Okay < / Button >
< Button onClick = { noop } >
This is a button with a fairly large amount of text
< / Button >
< Button onClick = { noop } > Okay < / Button >
< Button onClick = { noop } >
This is a button with a fairly large amount of text
< / Button >
< Button onClick = { noop } > Okay < / Button >
< / Modal.ButtonFooter >
< / Modal >
2022-06-07 00:48:02 +00:00
) ;
StickyFooterLotsOfButtons . story = {
name : 'Sticky footer, Lots of buttons' ,
} ;
2022-07-21 00:07:09 +00:00
export const WithBackButton = ( ) : JSX . Element = > (
< Modal
hasXButton
i18n = { i18n }
onBackButtonClick = { noop }
useFocusTrap = { false }
title = "The Modal Title"
>
Hello world !
< / Modal >
) ;
WithBackButton . story = {
name : 'Back Button' ,
} ;