Skip to content

Commit

Permalink
chore: move Button propTypes
Browse files Browse the repository at this point in the history
For better readability and fix eslint warning
  • Loading branch information
dinarosv committed Nov 15, 2021
1 parent face07f commit ff1a9c7
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 124 deletions.
241 changes: 119 additions & 122 deletions packages/dnb-eufemia/src/components/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,73 +35,6 @@ import Tooltip from '../tooltip/Tooltip'
export const buttonVariantPropType = {
variant: PropTypes.oneOf(['primary', 'secondary', 'tertiary', 'signal']),
}
export const buttonPropTypes = {
text: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
type: PropTypes.string,
title: PropTypes.node,
variant: buttonVariantPropType.variant,
size: PropTypes.oneOf(['default', 'small', 'medium', 'large']),
icon: PropTypes.oneOfType([
PropTypes.string,
PropTypes.node,
PropTypes.func,
]),
icon_position: PropTypes.oneOf(['left', 'right', 'top']),
icon_size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
tooltip: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
PropTypes.node,
]),
status: PropTypes.oneOfType([
PropTypes.string,
PropTypes.bool,
PropTypes.func,
PropTypes.node,
]),
status_state: PropTypes.string,
status_props: PropTypes.object,
status_no_animation: PropTypes.oneOfType([
PropTypes.string,
PropTypes.bool,
]),
global_status_id: PropTypes.string,
id: PropTypes.string,
class: PropTypes.string,
href: PropTypes.string,
to: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
PropTypes.func,
]),
custom_content: PropTypes.node,
wrap: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
bounding: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
stretch: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
skeleton: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
disabled: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
inner_ref: PropTypes.object,

className: PropTypes.string,
innerRef: PropTypes.object,
children: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
PropTypes.node,
]),
element: PropTypes.oneOfType([
PropTypes.func,
PropTypes.object,
PropTypes.node,
]),

...spacingPropTypes,

custom_element: PropTypes.object,
custom_method: PropTypes.func,

on_click: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
}

/**
* The button component should be used as the call-to-action in a form, or as a user interaction mechanism. Generally speaking, a button should not be used when a link would do the trick. Exceptions are made at times when it is used as a navigation element in the action-nav element.
Expand All @@ -110,48 +43,6 @@ export default class Button extends React.PureComponent {
static tagName = 'dnb-button'
static contextType = Context

static propTypes = {
...buttonPropTypes,
}

static defaultProps = {
type: null, // set the type because of the anchor/href situation – can be made more smart in future
text: null,
variant: null,
size: null,
title: null,
icon: null,
icon_position: 'right',
icon_size: null,
href: null,
to: null,
id: null,
class: null,
custom_content: null,
wrap: null,
bounding: null,
stretch: null,
skeleton: null,
disabled: null,
tooltip: null,
status: null,
status_state: 'error',
status_props: null,
status_no_animation: null,
global_status_id: null,
inner_ref: null,

className: null,
innerRef: null,
children: null,
element: null,

custom_element: null,
custom_method: null,

on_click: null,
}

static enableWebComponent() {
registerElement(Button?.tagName, Button, Button.defaultProps)
}
Expand Down Expand Up @@ -370,34 +261,110 @@ export default class Button extends React.PureComponent {
}
}

Content.propTypes = {
Button.propTypes = {
text: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
type: PropTypes.string,
title: PropTypes.node,
custom_content: PropTypes.node,
content: PropTypes.oneOfType([
variant: buttonVariantPropType.variant,
size: PropTypes.oneOf(['default', 'small', 'medium', 'large']),
icon: PropTypes.oneOfType([
PropTypes.string,
PropTypes.array,
PropTypes.node,
PropTypes.func,
]),
icon: PropTypes.oneOfType([
icon_position: PropTypes.oneOf(['left', 'right', 'top']),
icon_size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
tooltip: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
PropTypes.node,
]),
status: PropTypes.oneOfType([
PropTypes.string,
PropTypes.bool,
PropTypes.func,
PropTypes.node,
]),
status_state: PropTypes.string,
status_props: PropTypes.object,
status_no_animation: PropTypes.oneOfType([
PropTypes.string,
PropTypes.bool,
]),
global_status_id: PropTypes.string,
id: PropTypes.string,
class: PropTypes.string,
href: PropTypes.string,
to: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
PropTypes.func,
]),
icon_size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
custom_content: PropTypes.node,
wrap: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
bounding: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
skeleton: PropTypes.bool,
isIconOnly: PropTypes.bool,
stretch: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
skeleton: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
disabled: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
inner_ref: PropTypes.object,

className: PropTypes.string,
innerRef: PropTypes.object,
children: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
PropTypes.node,
]),
element: PropTypes.oneOfType([
PropTypes.func,
PropTypes.object,
PropTypes.node,
]),

...spacingPropTypes,

custom_element: PropTypes.object,
custom_method: PropTypes.func,

on_click: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
}

Content.defaultProps = {
custom_content: null,
Button.defaultProps = {
type: null, // set the type because of the anchor/href situation – can be made more smart in future
text: null,
variant: null,
size: null,
title: null,
content: null,
icon: null,
icon_size: 'default',
icon_position: 'right',
icon_size: null,
href: null,
to: null,
id: null,
class: null,
custom_content: null,
wrap: null,
bounding: null,
stretch: null,
skeleton: null,
isIconOnly: null,
disabled: null,
tooltip: null,
status: null,
status_state: 'error',
status_props: null,
status_no_animation: null,
global_status_id: null,
inner_ref: null,

className: null,
innerRef: null,
children: null,
element: null,

custom_element: null,
custom_method: null,

on_click: null,
}

function Content({
Expand Down Expand Up @@ -470,3 +437,33 @@ function Content({
</>
)
}

Content.propTypes = {
title: PropTypes.node,
custom_content: PropTypes.node,
content: PropTypes.oneOfType([
PropTypes.string,
PropTypes.array,
PropTypes.node,
]),
icon: PropTypes.oneOfType([
PropTypes.string,
PropTypes.node,
PropTypes.func,
]),
icon_size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
bounding: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
skeleton: PropTypes.bool,
isIconOnly: PropTypes.bool,
}

Content.defaultProps = {
custom_content: null,
title: null,
content: null,
icon: null,
icon_size: 'default',
bounding: null,
skeleton: null,
isIconOnly: null,
}
4 changes: 2 additions & 2 deletions packages/dnb-eufemia/src/components/help-button/HelpButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import { registerElement } from '../../shared/component-helper'
import Context from '../../shared/Context'
import Modal from '../modal/Modal'
import HelpButtonInstance from './HelpButtonInstance'
import { buttonPropTypes } from '../button/Button'
import Button from '../button/Button'

export default class HelpButton extends React.PureComponent {
static contextType = Context
static tagName = 'dnb-help-button'

static propTypes = {
...buttonPropTypes,
...Button.propTypes,
icon: PropTypes.oneOfType([
PropTypes.string,
PropTypes.node,
Expand Down

0 comments on commit ff1a9c7

Please sign in to comment.