Skip to content

Commit

Permalink
EditLayoutButton: replaced to ui folder, added props description and …
Browse files Browse the repository at this point in the history
…stories
  • Loading branch information
dmytroshch committed Feb 2, 2022
1 parent 0b3c501 commit f0ca80a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export { default as OrderForm } from './OrderForm'
export * from './Balances'
export * from './DepthChart'
export * from './Movements'
export { default as EditLayoutButton } from './EditLayoutButton'
export { default as EditLayoutButton } from './ui/EditLayoutButton'
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import PropTypes from 'prop-types'
import React from 'react'
import React, { memo } from 'react'
import { useTranslation } from 'react-i18next'

import withI18nProvider from '../../hoc/withI18nProvider'
import Button from '../ui/Button'
import withI18nProvider from '../../../hoc/withI18nProvider'
import Button from '../Button'

const EditLayoutButton = (props) => {
const {
layoutIsEditable,
enableEditLayout,
closeEditLayout,
} = props
export const EditLayoutButton = ({
layoutIsEditable,
enableEditLayout,
closeEditLayout,
}) => {
const { t } = useTranslation()

const label = layoutIsEditable
Expand All @@ -37,8 +36,18 @@ const EditLayoutButton = (props) => {
}

EditLayoutButton.propTypes = {
/**
* Callback, that enable editing layout (open modal)
*/
enableEditLayout: PropTypes.func,
/**
* If true, button's text is "Edit layout",
* if false - "Close edit"
*/
layoutIsEditable: PropTypes.bool,
/**
* Callback, that close editing (close modal)
*/
closeEditLayout: PropTypes.func,
}

Expand All @@ -48,4 +57,4 @@ EditLayoutButton.defaultProps = {
closeEditLayout: () => {},
}

export default withI18nProvider(EditLayoutButton)
export default withI18nProvider(memo(EditLayoutButton))
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { useCallback, useState } from 'react'

import {
showTemplateStory,
getDefaultMetadata,
} from '../../../../../../storybook/.storybook/helper'
import Modal from '../../Dialog'
import Button, { EditLayoutButton } from '../EditLayoutButton'

export default getDefaultMetadata(
EditLayoutButton,
'Components/ui/EditLayoutButton',
)

const Component = () => {
const [isShowingModal, setModalShowing] = useState(false)

const onClose = useCallback(() => setModalShowing(false), [])

return (
<>
<Button
layoutIsEditable={isShowingModal}
enableEditLayout={() => setModalShowing(true)}
closeEditLayout={onClose}
/>
<Modal
title='Edit Layout Modal'
isOpen={isShowingModal}
onClose={onClose}
>
Here you can edit layout
<Modal.Footer>
<Modal.Button primary onClick={onClose}>
OK
</Modal.Button>
</Modal.Footer>
</Modal>
</>
)
}
export const basic = showTemplateStory(Component, {})

0 comments on commit f0ca80a

Please sign in to comment.