Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 21 additions & 28 deletions components/dash-core-components/src/components/Checklist.react.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import PropTypes from 'prop-types';
import {append, includes, without} from 'ramda';
import React, {Component} from 'react';
import {optionsType} from "../utils/sharedPropTypes";
import {mapOptions} from "../utils/shorthandMappers";

/**
* Checklist is a component that encapsulates several checkboxes.
Expand All @@ -17,6 +19,7 @@ export default class Checklist extends Component {
inputStyle,
labelClassName,
labelStyle,
inline,
options,
setProps,
style,
Expand All @@ -33,10 +36,13 @@ export default class Checklist extends Component {
style={style}
className={className}
>
{options.map(option => (
{mapOptions(options).map(option => (
<label
key={option.value}
style={labelStyle}
style={{
...{display: inline ? 'inline-block' : "block"},
...labelStyle
}}
className={labelClassName}
>
<input
Expand Down Expand Up @@ -64,39 +70,20 @@ export default class Checklist extends Component {
}

Checklist.propTypes = {
/**
* An array of dictionaries as [{label: "Label", value: "Value"}],
* OR an array of options as ["Option 1", "Option 2"]
* OR an Object of options as {"Label 1": "Value 1", "Label 2": "Value 2"}
*/
options: optionsType,

/**
* The ID of this component, used to identify dash components
* in callbacks. The ID needs to be unique across all of the
* components in an app.
*/
id: PropTypes.string,

/**
* An array of options
*/
options: PropTypes.arrayOf(
PropTypes.exact({
/**
* The checkbox's label
*/
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
.isRequired,

/**
* The value of the checkbox. This value
* corresponds to the items specified in the
* `value` property.
*/
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
.isRequired,

/**
* If true, this checkbox is disabled and can't be clicked on.
*/
disabled: PropTypes.bool,
})
),

/**
* The currently selected value
*/
Expand Down Expand Up @@ -130,6 +117,11 @@ Checklist.propTypes = {
*/
labelStyle: PropTypes.object,

/**
* Shorthand for applying {'display': 'inline-block'} labelStyle
*/
inline: PropTypes.bool,

/**
* The class of the <label> that wraps the checkbox input
* and the option's label
Expand Down Expand Up @@ -194,6 +186,7 @@ Checklist.defaultProps = {
inputClassName: '',
labelStyle: {},
labelClassName: '',
inline: false,
options: [],
value: [],
persisted_props: ['value'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import React, {Component, lazy, Suspense} from 'react';
import dropdown from '../utils/LazyLoader/dropdown';
import {optionsType} from "../utils/sharedPropTypes";

const RealDropdown = lazy(dropdown);

Expand All @@ -25,47 +26,20 @@ export default class Dropdown extends Component {
}

Dropdown.propTypes = {
/**
* An array of dictionaries as [{label: "Label", value: "Value"}],
* OR an array of options as ["Option 1", "Option 2"]
* OR an Object of options as {"Label 1": "Value 1", "Label 2": "Value 2"}
*/
options: optionsType,

/**
* The ID of this component, used to identify dash components
* in callbacks. The ID needs to be unique across all of the
* components in an app.
*/
id: PropTypes.string,

/**
* An array of options {label: [string|number], value: [string|number]},
* an optional disabled field can be used for each option
*/
options: PropTypes.arrayOf(
PropTypes.exact({
/**
* The dropdown's label
*/
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
.isRequired,

/**
* The value of the dropdown. This value
* corresponds to the items specified in the
* `value` property.
*/
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
.isRequired,

/**
* If true, this option is disabled and cannot be selected.
*/
disabled: PropTypes.bool,

/**
* The HTML 'title' attribute for the option. Allows for
* information on hover. For more information on this attribute,
* see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title
*/
title: PropTypes.string,
})
),

/**
* The value of the input. If `multi` is false (the default)
* then value is just a string that corresponds to the values
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import PropTypes from 'prop-types';
import React, {Component} from 'react';
import './css/react-select@1.0.0-rc.3.min.css';
import {optionsType} from "../utils/sharedPropTypes";
import {mapOptions} from "../utils/shorthandMappers";

/**
* RadioItems is a component that encapsulates several radio item inputs.
Expand All @@ -19,6 +21,7 @@ export default class RadioItems extends Component {
inputStyle,
labelClassName,
labelStyle,
inline,
options,
setProps,
loading_state,
Expand All @@ -38,9 +41,12 @@ export default class RadioItems extends Component {
className={className}
style={style}
>
{options.map(option => (
{mapOptions(options).map(option => (
<label
style={labelStyle}
style={{
...{display: inline ? 'inline-block' : "block"},
...labelStyle
}}
className={labelClassName}
key={option.value}
>
Expand All @@ -63,39 +69,20 @@ export default class RadioItems extends Component {
}

RadioItems.propTypes = {
/**
* An array of dictionaries as [{label: "Label", value: "Value"}],
* OR an array of options as ["Option 1", "Option 2"]
* OR an Object of options as {"Label 1": "Value 1", "Label 2": "Value 2"}
*/
options: optionsType,

/**
* The ID of this component, used to identify dash components
* in callbacks. The ID needs to be unique across all of the
* components in an app.
*/
id: PropTypes.string,

/**
* An array of options
*/
options: PropTypes.arrayOf(
PropTypes.exact({
/**
* The radio item's label
*/
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
.isRequired,

/**
* The value of the radio item. This value
* corresponds to the items specified in the
* `value` property.
*/
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
.isRequired,

/**
* If true, this radio item is disabled and can't be clicked on.
*/
disabled: PropTypes.bool,
})
),

/**
* The currently selected value
*/
Expand Down Expand Up @@ -127,6 +114,11 @@ RadioItems.propTypes = {
*/
labelStyle: PropTypes.object,

/**
* Shorthand for applying {'display': 'inline-block'} labelStyle
*/
inline: PropTypes.bool,

/**
* The class of the <label> that wraps the radio input
* and the option's label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ export default class RangeSlider extends Component {
}

RangeSlider.propTypes = {
/**
* Minimum allowed value of the slider
*/
min: PropTypes.number,

/**
* Maximum allowed value of the slider
*/
max: PropTypes.number,

/**
* The ID of this component, used to identify dash components
* in callbacks. The ID needs to be unique across all of the
Expand Down Expand Up @@ -88,16 +98,6 @@ RangeSlider.propTypes = {
*/
included: PropTypes.bool,

/**
* Minimum allowed value of the slider
*/
min: PropTypes.number,

/**
* Maximum allowed value of the slider
*/
max: PropTypes.number,

/**
* pushable could be set as true to allow pushing of
* surrounding handles when moving an handle.
Expand Down
17 changes: 12 additions & 5 deletions components/dash-core-components/src/fragments/Dropdown.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import '../components/css/react-virtualized@9.9.0.css';
import '../components/css/Dropdown.css';

import {propTypes, defaultProps} from '../components/Dropdown.react';
import {mapOptions} from "../utils/shorthandMappers";

// Custom tokenizer, see https://github.com/bvaughn/js-search/issues/43
// Split on spaces
Expand All @@ -25,19 +26,25 @@ const DELIMETER = ',';
export default class Dropdown extends Component {
constructor(props) {
super(props);
const formattedOptions = mapOptions(props.options)

this.state = {
options: formattedOptions,
filterOptions: createFilterOptions({
options: props.options,
options: formattedOptions,
tokenizer: TOKENIZER,
}),
};
}

UNSAFE_componentWillReceiveProps(newProps) {
if (newProps.options !== this.props.options) {
const formattedOptions = mapOptions(newProps.options)

this.setState({
options: formattedOptions,
filterOptions: createFilterOptions({
options: newProps.options,
options: formattedOptions,
tokenizer: TOKENIZER,
}),
});
Expand All @@ -49,19 +56,19 @@ export default class Dropdown extends Component {
id,
clearable,
multi,
options,
setProps,
style,
loading_state,
value,
} = this.props;
const {filterOptions} = this.state;
const {options, filterOptions} = this.state;
let selectedValue;
if (type(value) === 'array') {
selectedValue = value.join(DELIMETER);
} else {
selectedValue = value;
}

return (
<div
id={id}
Expand Down Expand Up @@ -98,7 +105,7 @@ export default class Dropdown extends Component {
backspaceRemoves={clearable}
deleteRemoves={clearable}
inputProps={{autoComplete: 'off'}}
{...omit(['setProps', 'value'], this.props)}
{...omit(['setProps', 'value', 'options'], this.props)}
/>
</div>
);
Expand Down
Loading