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

DEP Upgrade bootstrap and reactstrap #1889

Merged
Merged
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
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/js/vendor.js

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions client/dist/styles/bundle.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/src/components/Accordion/AccordionBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const AccordionBlock = (props) => {
<div className="accordion__block">
<a
className="accordion__title"
data-toggle="collapse"
data-bs-toggle="collapse"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://getbootstrap.com/docs/5.0/migration/#javascript

Data attributes for all JavaScript plugins are now namespaced to help distinguish Bootstrap functionality from third parties and your own code. For example, we use data-bs-toggle instead of data-toggle.

Other data-* attributes that need changing seem to only need to be changed if data-bs-toggle is also present - see this third-party script which seems to list all the relevant attributes (I didn't run this, just used it as a guide)

href={`#${listIDAttr}`}
aria-expanded="true"
aria-controls={listID}
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/Badge/Badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class Badge extends PureComponent {
return null;
}

const invertedClass = inverted ? `badge-${status}--inverted` : '';
const colourClass = inverted ? `text-bg-${status}--inverted` : `text-bg-${status}`;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://getbootstrap.com/docs/5.0/migration/#badges

Dropped all .badge-* color classes for background utilities (e.g., use .bg-primary instead of .badge-primary).

Note that as of bootstrap 5.2 the text-bg-* is available which is what I opted for here. See https://getbootstrap.com/docs/5.2/helpers/color-background/


const compiledClassNames = classnames(
className,
'badge',
`badge-${status}`,
invertedClass,
colourClass,
);
return (
<span className={compiledClassNames}>
Expand All @@ -48,7 +48,7 @@ Badge.propTypes = {

Badge.defaultProps = {
status: 'default',
className: 'badge-pill',
className: 'rounded-pill',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://getbootstrap.com/docs/5.0/migration/#badges

Dropped .badge-pill—use the .rounded-pill utility instead.

inverted: false,
};

Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Badge/Badge.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// Inverted states
@each $color, $value in $theme-colors {
.badge-#{$color}--inverted {
.text-bg-#{$color}--inverted {
@include badge-variant-inverted($value);
}
}
10 changes: 5 additions & 5 deletions client/src/components/Badge/mixins/_badge.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Provides an inverted variant of Bootstrap badges.
// See: bootstrap/mixins/_badge.scss for original.
// Provides an inverted variant of Bootstrap 5's .text-bg-{color} classes which replace the old .badge-{color} classes.
@mixin badge-variant-inverted($bg) {
color: $bg;
background-color: color-yiq($bg);
background-color: color-contrast($bg);

Comment on lines -5 to +4
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://getbootstrap.com/docs/5.0/migration/#sass

Renamed color-yiq() function and related variables to color-contrast()

&[href] {
@include hover-focus {
&:hover,
&:focus {
color: darken($bg, 10%);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://getbootstrap.com/docs/5.0/migration/#sass

Removed previously deprecated mixins:

  • hover, hover-focus, plain-hover-focus, and hover-focus-active

background-color: color-yiq($bg);
background-color: color-contrast($bg);
}
}
}
6 changes: 3 additions & 3 deletions client/src/components/Badge/tests/Badge-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export default {
control: 'inline-radio',
options: {
'Empty class name': '',
'badge-pill class name': 'badge-pill'
'rounded-pill class name': 'rounded-pill'
},
table: {
type: { summary: 'string' },
defaultValue: { summary: 'badge-pill' },
defaultValue: { summary: 'rounded-pill' },
},
}
}
Expand All @@ -60,7 +60,7 @@ export const _Badge = {
args: {
message: 'Hello World!',
status: 'default',
className: 'badge-pill',
className: 'rounded-pill',
inverted: false
}
};
2 changes: 1 addition & 1 deletion client/src/components/Badge/tests/Badge-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test('Badge render() should return a Bootstrap style badge when valid', () => {
/>
);
expect(container.querySelectorAll('.badge').length).toBe(1);
expect(container.querySelectorAll('.badge-success').length).toBe(1);
expect(container.querySelectorAll('.text-bg-success').length).toBe(1);
expect(container.querySelectorAll('.customclass').length).toBe(1);
expect(container.innerHTML).toContain('Hello world');
});
2 changes: 1 addition & 1 deletion client/src/components/Breadcrumb/Breadcrumb.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
max-height: $toolbar-height;
overflow: hidden;

@include media-breakpoint-down(sm) {
@include media-breakpoint-down(md) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://getbootstrap.com/docs/5.0/migration/#sass

media-breakpoint-down() uses the breakpoint itself instead of the next breakpoint (e.g., media-breakpoint-down(lg) instead of media-breakpoint-down(md) targets viewports smaller than lg).

margin-left: $toolbar-total-height;

.toolbar__back-button + & {
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Button/BackButton.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
color: $text-muted; // TEMP: Needed for anchor buttons to override legacy styles
margin-left: -$spacer-xs;

@include media-breakpoint-down(sm) {
@include media-breakpoint-down(md) {
margin-left: 42px;

.insert-media-modal & {
Expand Down
21 changes: 12 additions & 9 deletions client/src/components/FieldHolder/FieldHolder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { FormGroup, InputGroup, InputGroupAddon, Label } from 'reactstrap';
import { FormGroup, InputGroup, InputGroupText, Label } from 'reactstrap';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://reactstrap.github.io/?path=/story/home-upgrading--page

InputGroupAddon - This in no longer needed in Bootstrap 5, you can now add Buttons, Inputs directly to InputGroups in the order you wish.

Note that InputGroupAddon used to implicitly add a InputGroupText if it was a string being added, so I've opted to keep that behaviour here.

import castStringToElement from 'lib/castStringToElement';
import classnames from 'classnames';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -42,6 +42,7 @@ function fieldHolder(Field) {
field: true,
[this.props.extraClass]: true,
readonly: this.props.readOnly,
'form-group': true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://getbootstrap.com/docs/5.0/migration/#sass

Dropped form-specific layout classes for our grid system. Use our grid and utilities instead of .form-group, .form-row, or .form-inline.

It would require a non-trivial amount of effort to do that refactor and I like how semantic these class names are, so I opted instead to port those styles into client/src/styles/_bootstrap-form.scss instead.

Reactstrap correctly stopped adding these css classes, so I've added them back where necessary.

}),
id: this.props.holderId,
};
Expand Down Expand Up @@ -126,20 +127,22 @@ function fieldHolder(Field) {
};

const field = <Field {...props} />;
const prefix = this.props.data && this.props.data.prefix ? this.props.data.prefix : '';
const suffix = this.props.data && this.props.data.suffix ? this.props.data.suffix : '';
let prefix = this.props.data && this.props.data.prefix ? this.props.data.prefix : '';
let suffix = this.props.data && this.props.data.suffix ? this.props.data.suffix : '';
if (!prefix && !suffix) {
return field;
}
if (prefix !== '' && typeof prefix === 'string') {
prefix = <InputGroupText>{prefix}</InputGroupText>;
}
if (suffix !== '' && typeof suffix === 'string') {
suffix = <InputGroupText>{suffix}</InputGroupText>;
}
return (
<InputGroup>
{prefix &&
<InputGroupAddon addonType="prepend">{prefix}</InputGroupAddon>
}
{prefix}
{field}
{suffix &&
<InputGroupAddon addonType="append">{suffix}</InputGroupAddon>
}
{suffix}
</InputGroup>
);
}
Expand Down
6 changes: 4 additions & 2 deletions client/src/components/FieldHolder/tests/FieldHolder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ test('FieldHolder prefix', () => {
}}
/>
);
expect(container.querySelector('.input-group-prepend .input-group-text').innerHTML).toBe('My prefix');
expect(container.querySelectorAll('.input-group-text')).toHaveLength(1);
expect(container.querySelector('.input-group .input-group-text').innerHTML).toBe('My prefix');
});

test('FieldHolder prefix', () => {
Expand All @@ -210,7 +211,8 @@ test('FieldHolder prefix', () => {
}}
/>
);
expect(container.querySelector('.input-group-append .input-group-text').innerHTML).toBe('My suffix');
expect(container.querySelectorAll('.input-group-text')).toHaveLength(1);
expect(container.querySelector('.input-group .input-group-text').innerHTML).toBe('My suffix');
});

test('FieldHolder titleTip should be rendered if one is provided', () => {
Expand Down
1 change: 0 additions & 1 deletion client/src/components/Form/Form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ input[type="checkbox"],
input[type="radio"],
input.checkbox,
input.radio {
display: inline;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does nothing in most cases due to the usage of float - but it was causing problems with the checkbox in userforms submissions area.

margin-right: 6px;
}

Expand Down
50 changes: 10 additions & 40 deletions client/src/components/FormAction/FormAction.scss
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
}

// Used buttons with text and icons, but you wan to hide the text only. eg. gridfield pagination
// Could change to BS .text-hide { @include text-hide(); }, although slightly different
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.text-hide changed and this comment seems kinda useless anyway ("although slightly different" - so we can't change it to that then?) so removed instead of updated

.btn--hide-text[class*="font-icon-"] {

&:before {
Expand Down Expand Up @@ -142,39 +141,6 @@
}
}


// Specific button variations
.btn-primary {
border-bottom-color: $btn-primary-shadow;

.btn__circle {
background: $white;
}

&:focus {
outline-color: $brand-primary;
}
}

.btn-outline-primary {
border-color: lighten($btn-primary-border, 10%);

&:not(:disabled, .disabled) {
&:hover,
&:active,
&:focus {
color: darken($btn-primary-bg, 10%);
background-image: none;
background-color: lighten($btn-primary-bg, 50%);
border-color: $btn-primary-border;
}
}

.btn__circle {
background: $btn-primary-bg;
}
}
Comment on lines -146 to -176
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seems to not affect the end result anymore


.btn-secondary {
border-color: transparent;
background-color: transparent;
Expand All @@ -200,13 +166,17 @@
&:not(:disabled, .disabled) {
&:hover,
&:focus,
&.focus,
&:active,
&.active {
&.focus {
background-color: $btn-secondary-bg;
border-color: $btn-secondary-bg;
color: $text-muted;
}
&:active,
&.active {
background-color: var(--bs-btn-active-bg);
border-color: var(--bs-btn-active-border-color);
color: var(--bs-btn-active-color);
}
Comment on lines -203 to +179
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

active needed to be split out to resolve colours being incorrect (e.g. search (magnifying glass) button in gridfields)

}
}

Expand Down Expand Up @@ -281,14 +251,14 @@

// Close buttons
// Bootstrap close button customizations
.close {
.btn-close {
Comment on lines -284 to +254
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://getbootstrap.com/docs/5.0/migration/#close-button

Renamed .close to .btn-close for a less generic name.

font-size: ($font-size-base * 1.8);
opacity: .3;
line-height: 20px;
display: block;
}

button.close {
button.btn-close {
padding: $input-btn-padding-y $input-btn-padding-x;
}

Expand All @@ -312,7 +282,7 @@ button.close {
}

.actions-warning {
color: #856404; // in bootstrap: theme-color-level(map-get($theme-colors, "yellow"), 6)
color: #856404; // in bootstrap: shift-color(map-get($theme-colors, "yellow"), 6)
Comment on lines -315 to +285
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://getbootstrap.com/docs/5.0/migration/#sass

Renamed theme-color-level() function to color-level() .... Watch out: color-level() was later on dropped in v5.0.0-alpha3.

https://getbootstrap.com/docs/5.0/migration/#color-system

The color system which worked with color-level() and $theme-color-interval was removed in favor of a new color system. ... The shift-color() will either tint or shade a color depending on whether its weight parameter is positive or negative. See #30622 for more details.


// override .btn styles
&.btn {
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/FormAlert/FormAlert.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.message-box .close {
.message-box .btn-close {
cursor: pointer;
padding-bottom: 0.9rem;
padding-top: 0.6rem;
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/GridField/GridField.scss
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ div.grid-field__sort-field + .form__fieldgroup-item {
.grid-field__icon-action--hidden-on-hover {
opacity: 0;

@include media-breakpoint-down(sm) {
@include media-breakpoint-down(md) {
opacity: 1;
}
}
Expand Down Expand Up @@ -243,7 +243,7 @@ div.grid-field__sort-field + .form__fieldgroup-item {


// Responsive grid-field
@include media-breakpoint-down(sm) {
@include media-breakpoint-down(md) {
.grid-field__table td,
.grid-field__table th {
display: none;
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/GridFieldActions/GridFieldActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GridFieldActions extends PureComponent {
return groupsList;
}, []);

const dropdownMenuProps = { right: true };
const dropdownMenuProps = { end: true };
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://reactstrap.github.io/?path=/story/home-upgrading--page

Dropdown/DropdownMenu - The left and right properties are deprecated, but still supported for backwards compatibility. Now replaced with start and end in Bootstrap 5.

const dropdownToggleClassNames = [
'action-menu__toggle',
'btn',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test('GridFieldActions.render() should render a menu, if there is more than one
}}
/>
);
expect(container.querySelector('.action-menu__toggle .sr-only').innerHTML).toBe('View actions');
expect(container.querySelector('.action-menu__toggle .visually-hidden').innerHTML).toBe('View actions');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://getbootstrap.com/docs/5.0/migration/#helpers

Renamed .sr-only and .sr-only-focusable to .visually-hidden and .visually-hidden-focusable

});

test('GridFieldActions.renderSingleAction() should render a button', () => {
Expand Down
13 changes: 5 additions & 8 deletions client/src/components/InputField/InputField.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { Component } from 'react';
import {
Input,
InputGroup,
InputGroupAddon,
} from 'reactstrap';
import PropTypes from 'prop-types';

Expand Down Expand Up @@ -69,13 +68,11 @@ class InputField extends Component {
return (
<InputGroup>
<Input {...this.getInputProps()} />
<InputGroupAddon addonType="append">
<Tip
{...tip}
fieldTitle={title}
id={`${id}-tip`}
/>
</InputGroupAddon>
<Tip
{...tip}
fieldTitle={title}
id={`${id}-tip`}
/>
</InputGroup>
);
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/LabelField/LabelField.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';

const LabelField = ({ id, className, title, extraClass, data }) => {
const htmlFor = data && data.target;
const classes = `${className} ${extraClass}`;
const classes = `form-label ${className} ${extraClass}`;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://getbootstrap.com/docs/5.0/migration/#forms

Form labels now require .form-label.


return (
<label id={id} className={classes} htmlFor={htmlFor}>{title}</label>
Expand Down
Loading
Loading