Skip to content

Commit

Permalink
feat(Confirm): allow custom sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
ashurbeyli committed Jan 10, 2018
1 parent 7ef9fdb commit 339dd78
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
25 changes: 25 additions & 0 deletions docs/app/Examples/addons/Confirm/Variations/ConfirmExampleSize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { Component } from 'react'
import { Button, Confirm } from 'semantic-ui-react'

export default class ConfirmExampleSize extends Component {
state = { open: false }

handleButtonClick = () => this.setState({ open: true })
handleConfirm = () => this.setState({ open: false })
handleCancel = () => this.setState({ open: false })

render() {
return (
<div>
<Button onClick={this.handleButtonClick}>Show Large</Button>
<Confirm
header='This is a large confirm'
open={this.state.open}
onCancel={this.handleCancel}
onConfirm={this.handleConfirm}
size='large'
/>
</div>
)
}
}
5 changes: 5 additions & 0 deletions docs/app/Examples/addons/Confirm/Variations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const ConfirmVariationsExamples = () => (
description='A confirm can customize button text.'
examplePath='addons/Confirm/Variations/ConfirmExampleButtons'
/>
<ComponentExample
title='Confirm Size'
description='A confirm can define size.'
examplePath='addons/Confirm/Variations/ConfirmExampleSize'
/>
</ExampleSection>
)

Expand Down
3 changes: 3 additions & 0 deletions src/addons/Confirm/Confirm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export interface ConfirmProps extends ModalProps {

/** Whether or not the modal is visible. */
open?: boolean;

/** A confirm can vary in size. */
size?: 'fullscreen' | 'large' | 'mini' | 'small' | 'tiny';
}

declare const Confirm: React.ComponentClass<ConfirmProps>;
Expand Down
7 changes: 6 additions & 1 deletion src/addons/Confirm/Confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ class Confirm extends Component {

/** Whether or not the modal is visible. */
open: PropTypes.bool,

/** A Confirm can vary in size */
size: PropTypes.oneOf(['fullscreen', 'large', 'mini', 'small', 'tiny']),
}

static defaultProps = {
cancelButton: 'Cancel',
confirmButton: 'OK',
content: 'Are you sure?',
size: 'small',
}

static _meta = {
Expand Down Expand Up @@ -84,6 +88,7 @@ class Confirm extends Component {
content,
header,
open,
size,
} = this.props
const rest = getUnhandledProps(Confirm, this.props)

Expand All @@ -94,7 +99,7 @@ class Confirm extends Component {
if (_.has(this.props, 'open')) openProp.open = open

return (
<Modal {...rest} {...openProp} size='small' onClose={this.handleCancel}>
<Modal {...rest} {...openProp} size={size} onClose={this.handleCancel}>
{Modal.Header.create(header)}
{Modal.Content.create(content)}
<Modal.Actions>
Expand Down
28 changes: 20 additions & 8 deletions test/specs/addons/Confirm/Confirm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ let wrapper
// we need to unmount the modal after every test to remove it from the document
// wrap the render methods to update a global wrapper that is unmounted after each test
const wrapperMount = (...args) => (wrapper = mount(...args))
const wrapperShallow = (...args) => (wrapper = shallow(...args))

describe('Confirm', () => {
beforeEach(() => {
Expand All @@ -40,13 +39,26 @@ describe('Confirm', () => {
mapValueToProps: content => ({ content }),
})

it('renders a small Modal', () => {
wrapperShallow(<Confirm />)
wrapper
.type()
.should.equal(Modal)
wrapper
.should.have.prop('size', 'small')
describe('children', () => {
it('renders a Modal', () => {
shallow(<Confirm />)
.type()
.should.equal(Modal)
})
})

describe('size', () => {
it('has "small" size by default', () => {
shallow(<Confirm />)
.should.have.prop('size', 'small')
})

_.forEach(['fullscreen', 'large', 'mini', 'small', 'tiny'], (size) => {
it(`applies ${size} size`, () => {
shallow(<Confirm size={size} />)
.should.have.prop('size', size)
})
})
})

describe('cancelButton', () => {
Expand Down

0 comments on commit 339dd78

Please sign in to comment.