Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap 5 support #646

Merged
merged 55 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
277a236
Alert
tcbegley Aug 13, 2021
e90cbe6
Badge
tcbegley Aug 13, 2021
e778c16
Button
tcbegley Aug 13, 2021
ebb6f07
ButtonGroup
tcbegley Aug 13, 2021
63fc30d
Carousel
tcbegley Aug 13, 2021
4fa4b02
Collapse
tcbegley Aug 13, 2021
1edb13e
Fade
tcbegley Aug 14, 2021
fb7d43e
Add shim for html components that don't have class_name defined yet
tcbegley Aug 15, 2021
c44f53c
Update block button docs
tcbegley Aug 15, 2021
7123398
Update docs for Bootstrap 5
tcbegley Aug 15, 2021
cf68a38
RIP Jumbotron
tcbegley Aug 15, 2021
ac33e0e
Add react-bootstrap beta
tcbegley Aug 15, 2021
5c5af30
Layout
tcbegley Aug 15, 2021
54148ef
Docs fix
tcbegley Aug 15, 2021
6134398
Label
tcbegley Aug 15, 2021
c8c2949
Clean up example
tcbegley Aug 15, 2021
5f780b0
Monkeypatch doc tests
tcbegley Aug 15, 2021
42403e3
New components - Offcanvas and pagination (#643)
glsdown Aug 15, 2021
3412cca
Progress
tcbegley Aug 15, 2021
226791f
Format tests
tcbegley Aug 15, 2021
164207f
Spinner
tcbegley Aug 15, 2021
98d44e7
Table
tcbegley Aug 15, 2021
1f81d56
Toast
tcbegley Aug 15, 2021
793b3c1
New component Accordion (#645)
glsdown Aug 15, 2021
2b33232
flake8 config
tcbegley Aug 15, 2021
67dd011
List group updated to Bootstrap 5 (#647)
glsdown Aug 16, 2021
14fdeed
Bug fixes
tcbegley Aug 16, 2021
285e284
Tabs
tcbegley Aug 16, 2021
717d7b7
Form
tcbegley Aug 16, 2021
38a562e
Form updates + examples
tcbegley Aug 17, 2021
bfd42b0
Checklist / RadioItems
tcbegley Aug 18, 2021
a857394
Select
tcbegley Aug 18, 2021
ab47de0
themes
tcbegley Aug 18, 2021
a65f47e
BS5 updates for docs
tcbegley Aug 18, 2021
5fc033a
Fix doc tests
tcbegley Aug 18, 2021
e4c29bb
InputGroup
tcbegley Aug 18, 2021
80e5d36
Fix JS tests
tcbegley Aug 18, 2021
f9b53af
Checkbox/Radio
tcbegley Aug 18, 2021
5aea7e3
format js
tcbegley Aug 18, 2021
1ef7b40
Modal
tcbegley Aug 18, 2021
506a000
Modal docs
tcbegley Aug 18, 2021
b0ed5a4
Fix format command
tcbegley Aug 19, 2021
932cb0a
Card, Nav and Navbar (#648)
AnnMarieW Aug 20, 2021
bc22e9e
DropdownMenu
tcbegley Aug 20, 2021
d4d760d
NavbarToggler
tcbegley Aug 21, 2021
57716c6
Tooltip+Popover
tcbegley Aug 21, 2021
ce07d3e
Consistent imports
tcbegley Aug 21, 2021
d70f885
Fix accordion tests
tcbegley Aug 22, 2021
8431e7d
Initial breadcrumb component
tcbegley Aug 22, 2021
47dced1
Set accordion to first component
tcbegley Aug 22, 2021
3151b6a
Format code
tcbegley Aug 22, 2021
a0aef08
Update Breadcrumb
tcbegley Aug 22, 2021
dee3f2a
Snippet test fixes for breadcrumb
tcbegley Aug 22, 2021
54de8a0
Popover - minor prop updates (#652)
AnnMarieW Aug 24, 2021
7a539e1
Use size prop consistently
tcbegley Aug 24, 2021
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
Prev Previous commit
Next Next commit
Form
  • Loading branch information
tcbegley committed Aug 16, 2021
commit 717d7b752edbee80efabce30b1cfb0d30cded0d1
8 changes: 7 additions & 1 deletion docs/components_page/components/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ The `FormGroup` is the easiest way to add structure to forms. It encourages prop

{{example:components/form/simple.py:form}}


## Floating labels

Wrap an `Input` with `FloatingLabel` to create a label that floats over the form field.

{{example:components/form/floating.py:form}}
## Horizontal form

Create a horizontal form by setting `row=True` on the `FormGroup` component. Be sure to specify `width` on the `Label` component, and wrap your inputs in `Col` components.
Expand All @@ -35,7 +41,7 @@ Use the `valid` and `invalid` properties of `Input`, alongside the `FormFeedback

The `Input` component has two properties, `valid` and `invalid`, that can be set in callbacks. They can be used to indicate whether the input value is valid or invalid. When `valid=True`, the `Input` will be styled with a green colored border, similarly when `invalid=True` the input will be styled with a red colored border.

The `FormFeedback` component should be added to the `FormGroup` containing the `Input` it is associated with. Use the `valid` property to indicate whether the feedback should display for valid or invalid inputs. The feedback automatically display when the validity of the `Input` in the `FormGroup` matches that of the `FormFeedback`. This is perhaps easiest to see with an example such as the below.
The `FormFeedback` component should be added to the `FormGroup` containing the `Input` it is associated with. Use the `type` property to indicate whether the feedback should display for valid or invalid inputs, it accepts the strings `"valid"` or `"invalid"`. The feedback automatically display when the validity of the `Input` in the `FormGroup` matches that of the `FormFeedback`. This is perhaps easiest to see with an example such as the below.

{{example:components/form/feedback.py:email_input}}

Expand Down
4 changes: 2 additions & 2 deletions docs/components_page/components/form/feedback.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ email_input <- htmlDiv(
dbcInput(id = "email-input", type = "email", value = ""),
dbcFormText("We only accept gmail..."),
dbcFormFeedback(
"That looks like a gmail address :-)", valid = TRUE
"That looks like a gmail address :-)", type = "valid"
),
dbcFormFeedback(
"Sorry, we only accept gmail for some reason...",
valid = FALSE
type = "invalid"
)
)
)
Expand Down
4 changes: 2 additions & 2 deletions docs/components_page/components/form/feedback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ email_input = html_div([
dbc_label("Email"),
dbc_input(id="email-input", type="email", value=""),
dbc_formtext("We only accept gmail..."),
dbc_formfeedback("That looks like a gmail address :-)", valid=true),
dbc_formfeedback("Sorry, we only accept gmail for some reason...", valid=false),
dbc_formfeedback("That looks like a gmail address :-)", type="valid"),
dbc_formfeedback("Sorry, we only accept gmail for some reason...", type="invalid"),
]),
]);

Expand Down
4 changes: 2 additions & 2 deletions docs/components_page/components/form/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
dbc.Input(id="email-input", type="email", value=""),
dbc.FormText("We only accept gmail..."),
dbc.FormFeedback(
"That looks like a gmail address :-)", valid=True
"That looks like a gmail address :-)", type="valid"
),
dbc.FormFeedback(
"Sorry, we only accept gmail for some reason...",
valid=False,
type="invalid",
),
]
)
Expand Down
3 changes: 3 additions & 0 deletions docs/components_page/components/form/floating.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import dash_bootstrap_components as dbc

form = dbc.FloatingLabel(dbc.Input(type="email"), label="Email address")
1 change: 0 additions & 1 deletion docs/components_page/components/form/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@
),
dbc.Button("Submit", color="primary"),
],
inline=True,
)
6 changes: 3 additions & 3 deletions docs/components_page/components/form/row.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
width=10,
),
],
row=True,
class_name="row",
)

password_input = dbc.FormGroup(
Expand All @@ -25,7 +25,7 @@
width=10,
),
],
row=True,
class_name="row",
)

radios_input = dbc.FormGroup(
Expand All @@ -47,7 +47,7 @@
width=10,
),
],
row=True,
class_name="row",
)

form = dbc.Form([email_input, password_input, radios_input])
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
class_name="form-check-label",
),
],
check=True,
),
dbc.FormGroup(
[
Expand All @@ -28,7 +27,6 @@
class_name="form-check-label",
),
],
check=True,
),
html.Br(),
html.P(id="standalone-radio-check-output"),
Expand Down
4 changes: 2 additions & 2 deletions docs/demos/theme_explorer/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
[
dbc.Label("Valid text input"),
dbc.Input(type="text", valid=True),
dbc.FormFeedback("That's a valid input!", valid=True),
dbc.FormFeedback("That's a valid input!", type="valid"),
]
),
dbc.FormGroup(
[
dbc.Label("Invalid text input"),
dbc.Input(type="text", invalid=True),
dbc.FormFeedback("That's an invalid input..."),
dbc.FormFeedback("That's an invalid input...", type="invalid"),
]
),
]
Expand Down
100 changes: 100 additions & 0 deletions src/components/form/FloatingLabel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import React from 'react';
import PropTypes from 'prop-types';
import {omit} from 'ramda';
import {default as RBFloatingLabel} from 'react-bootstrap/FloatingLabel';

/**
* A component for adding float labels to form controls in forms.
*/
const FloatingLabel = props => {
const {
children,
html_for,
className,
class_name,
loading_state,
...otherProps
} = props;

// TODO: check this component
return (
<RBFloatingLabel
htmlFor={html_for}
className={class_name || className}
{...omit(['setProps'], otherProps)}
data-dash-is-loading={
(loading_state && loading_state.is_loading) || undefined
}
>
{children}
</RBFloatingLabel>
);
};

FloatingLabel.propTypes = {
/**
* 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,

/**
* The children of this component
*/
children: PropTypes.node,

/**
* Defines CSS styles which will override styles previously set.
*/
style: PropTypes.object,

/**
* Often used with CSS to style elements with common properties.
*/
class_name: PropTypes.string,

/**
* The text of the label.
*/
label: PropTypes.string,

/**
* **DEPRECATED** Use `class_name` instead.
*
* Often used with CSS to style elements with common properties.
*/
className: PropTypes.string,

/**
* A unique identifier for the component, used to improve
* performance by React.js while rendering components
* See https://reactjs.org/docs/lists-and-keys.html for more info
*/
key: PropTypes.string,

/**
* Set the `for` attribute of the label to bind it to a particular element
*/
html_for: PropTypes.string,

/**
* Object that holds the loading state object coming from dash-renderer
*/
loading_state: PropTypes.shape({
/**
* Determines if the component is loading or not
*/
is_loading: PropTypes.bool,
/**
* Holds which property is loading
*/
prop_name: PropTypes.string,
/**
* Holds the name of the component that is loading
*/
component_name: PropTypes.string
})
};

export default FloatingLabel;
13 changes: 3 additions & 10 deletions src/components/form/Form.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import {omit} from 'ramda';
import {Form as RSForm} from 'reactstrap';
import {default as RBForm} from 'react-bootstrap/Form';

/**
* The Form component can be used to organise collections of input components
Expand All @@ -19,7 +19,7 @@ const Form = (props) => {
...otherProps
} = props;
return (
<RSForm
<RBForm
onSubmit={(e) => {
if (prevent_default_on_submit) {
e.preventDefault();
Expand All @@ -38,7 +38,7 @@ const Form = (props) => {
}
>
{children}
</RSForm>
</RBForm>
);
};

Expand Down Expand Up @@ -96,13 +96,6 @@ Form.propTypes = {
*/
method: PropTypes.oneOf(['GET', 'POST']),

/**
* Use inline=True to apply the `form-inline` class, allowing you to display
* a series of labels, form controls, and buttons on a single horizontal row.
* Form controls within inline forms vary slightly from their default states.
*/
inline: PropTypes.bool,

/**
* Number of times the `Enter` key was pressed while the input had focus.
*/
Expand Down
17 changes: 8 additions & 9 deletions src/components/form/FormFeedback.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import React from 'react';
import PropTypes from 'prop-types';
import {omit} from 'ramda';
import {FormFeedback as RSFormFeedback} from 'reactstrap';
import FormControl from 'react-bootstrap/FormControl';

/**
* The FormFeedback component can be used to provide feedback on input values
* in a form. Add the form feedback to a `FormGroup` and set the `valid` or
* `invalid` props of the associated input to toggle visibility.
*/
const FormFeedback = (props) => {
const FormFeedback = props => {
const {children, loading_state, className, class_name, ...otherProps} = props;
return (
<RSFormFeedback
<FormControl.Feedback
className={class_name || className}
{...omit(['setProps'], otherProps)}
data-dash-is-loading={
(loading_state && loading_state.is_loading) || undefined
}
>
{children}
</RSFormFeedback>
</FormControl.Feedback>
);
};

Expand Down Expand Up @@ -61,10 +61,9 @@ FormFeedback.propTypes = {
key: PropTypes.string,

/**
* If True apply the valid styling to the feedback, else apply invalid
* styling.
* Either 'valid' or 'invalid'.
*/
valid: PropTypes.bool,
type: PropTypes.string,

/**
* Use styled tooltips to display validation feedback.
Expand All @@ -86,8 +85,8 @@ FormFeedback.propTypes = {
/**
* Holds the name of the component that is loading
*/
component_name: PropTypes.string,
}),
component_name: PropTypes.string
})
};

export default FormFeedback;
28 changes: 3 additions & 25 deletions src/components/form/FormGroup.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import React from 'react';
import PropTypes from 'prop-types';
import {omit} from 'ramda';
import {FormGroup as RSFormGroup} from 'reactstrap';
import {default as RBFormGroup} from 'react-bootstrap/FormGroup';

/**
* A component for grouping together inputs, labels, text and feedback.
*/
const FormGroup = (props) => {
const {children, loading_state, className, class_name, ...otherProps} = props;
return (
<RSFormGroup
<RBFormGroup
className={class_name || className}
{...omit(['setProps'], otherProps)}
data-dash-is-loading={
(loading_state && loading_state.is_loading) || undefined
}
>
{children}
</RSFormGroup>
</RBFormGroup>
);
};

Expand Down Expand Up @@ -58,28 +58,6 @@ FormGroup.propTypes = {
*/
key: PropTypes.string,

/**
* Apply row class to FormGroup to allow labels and inputs to be displayed
* horizontally in a row.
*/
row: PropTypes.bool,

/**
* Apply `form-check` class instead of `form-group`. Useful when positioning
* labels with checkbox / radio inputs. Usually it will be better to use the
* pre-built dbc.Checklist or dbc.RadioItems components.
*/
check: PropTypes.bool,

/**
* If check is True, apply the `form-check-inline` class in addition to
* `form-check`. If you want to make an inline list of checkboxes / radios
* we recommend using either dbc.Checklist or dbc.RadioItems with inline=True
*
* This prop has no effect if check=False.
*/
inline: PropTypes.bool,

/**
* Object that holds the loading state object coming from dash-renderer
*/
Expand Down
Loading