Skip to content

Commit 69602f8

Browse files
authored
Merge pull request #54 from makavelithadon/bootstrap-5
Add Bootstrap 5 support
2 parents 4064f77 + 019cf55 commit 69602f8

File tree

14 files changed

+65
-204
lines changed

14 files changed

+65
-204
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Next
2+
3+
### Breaking Changes
4+
5+
- Upgrade Bootstrap from v4 to v5
6+
17
## v0.17.0 (2021/05/16)
28

39
### Breaking Changes

examples/Bootstrap/App.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function Form() {
9494

9595
return (
9696
<FormWithConstraints ref={form} onSubmit={handleSubmit} noValidate>
97-
<div className="form-group">
97+
<div className="mb-3">
9898
<label htmlFor="username">
9999
Username <small>(already taken: john, paul, george, ringo)</small>
100100
</label>
@@ -116,7 +116,7 @@ function Form() {
116116
pending={<span className="d-block">...</span>}
117117
then={available =>
118118
available ? (
119-
<FieldFeedback key="1" info style={{ color: '#28a745' }}>
119+
<FieldFeedback key="1" info style={{ color: '#198754' /* $green */ }}>
120120
Username available
121121
</FieldFeedback>
122122
) : (
@@ -127,7 +127,7 @@ function Form() {
127127
<FieldFeedback when="valid">Looks good!</FieldFeedback>
128128
</FieldFeedbacks>
129129
</div>
130-
<div className="form-group">
130+
<div className="mb-3">
131131
<label htmlFor="password">Password</label>
132132
<Input
133133
type="password"
@@ -158,7 +158,7 @@ function Form() {
158158
<FieldFeedback when="valid">Looks good!</FieldFeedback>
159159
</FieldFeedbacks>
160160
</div>
161-
<div className="form-group">
161+
<div className="mb-3">
162162
<label htmlFor="password-confirm">Confirm Password</label>
163163
<Input
164164
type="password"

examples/Bootstrap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"test:e2e": "jest --config jest-e2e.config.js --verbose"
2222
},
2323
"dependencies": {
24-
"bootstrap": "^4.5.3",
24+
"bootstrap": "^5.0.1",
2525
"core-js": "^3.6.5",
2626
"lodash-es": "^4.17.15",
2727
"raf": "^3.4.1",

examples/ClubMembers/App.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ const Hobbies = observer<React.FunctionComponent<HobbiesProps>>(
131131
const hobbyName = `member${memberIndex}.hobby${index}`;
132132

133133
return (
134-
<li key={index} className="form-group">
135-
<div className="form-inline">
134+
<li key={index} className="mb-3">
135+
<div className="d-flex align-items-center">
136136
<Input
137137
name={hobbyName}
138138
id={hobbyName}
@@ -142,16 +142,15 @@ const Hobbies = observer<React.FunctionComponent<HobbiesProps>>(
142142
required
143143
minLength={3}
144144
className="form-control"
145-
style={{ width: 'auto' }}
146145
/>
146+
&nbsp;
147147
<button
148148
type="button"
149149
title="Remove Hobby"
150150
onClick={() => removeHobby(index)}
151-
className="close"
152-
>
153-
&times;
154-
</button>
151+
className="btn-close"
152+
aria-label="Close"
153+
/>
155154
</div>
156155
<FieldFeedbacks for={hobbyName}>
157156
<FieldFeedback when="*" />
@@ -164,7 +163,7 @@ const Hobbies = observer<React.FunctionComponent<HobbiesProps>>(
164163

165164
return (
166165
<>
167-
<div className="form-group">
166+
<div className="mb-3">
168167
<button
169168
type="button"
170169
name={checkNbHobbiesName}
@@ -179,7 +178,7 @@ const Hobbies = observer<React.FunctionComponent<HobbiesProps>>(
179178
</FieldFeedback>
180179
</FieldFeedbacks>
181180
</div>
182-
<ul className="list-none">
181+
<ul className="list-style-none">
183182
{member.hobbies.map((hobby, index) => renderHobby(hobby, index))}
184183
</ul>
185184
</>
@@ -224,17 +223,17 @@ const Members = observer<React.FunctionComponent<MembersProps>>(({ club, validat
224223
<li key={index}>
225224
<h4>
226225
Member #{index + 1}
226+
&nbsp;
227227
<button
228228
type="button"
229229
title="Remove Member"
230230
onClick={() => removeMember(index)}
231-
className="close"
232-
>
233-
&times;
234-
</button>
231+
className="btn-close fs-6"
232+
aria-label="Close"
233+
/>
235234
</h4>
236235

237-
<div className="form-group">
236+
<div className="mb-3">
238237
<Input
239238
name={memberFirstNameName}
240239
placeholder="First Name"
@@ -249,7 +248,7 @@ const Members = observer<React.FunctionComponent<MembersProps>>(({ club, validat
249248
</FieldFeedbacks>
250249
</div>
251250

252-
<div className="form-group">
251+
<div className="mb-3">
253252
<Input
254253
name={memberLastNameName}
255254
placeholder="Last Name"
@@ -271,7 +270,7 @@ const Members = observer<React.FunctionComponent<MembersProps>>(({ club, validat
271270

272271
return (
273272
<>
274-
<div className="form-group">
273+
<div className="mb-3">
275274
<button
276275
type="button"
277276
name="checkNbMembers"
@@ -286,7 +285,7 @@ const Members = observer<React.FunctionComponent<MembersProps>>(({ club, validat
286285
</FieldFeedback>
287286
</FieldFeedbacks>
288287
</div>
289-
<ul className="list-none">
288+
<ul className="list-style-none">
290289
{club.members.map((member, index) => renderMember(member, index))}
291290
</ul>
292291
</>
@@ -341,7 +340,7 @@ class Form extends React.Component<FormProps> {
341340
onSubmit={this.handleSubmit}
342341
noValidate
343342
>
344-
<div className="form-group">
343+
<div className="mb-3">
345344
<Input
346345
name="clubName"
347346
placeholder="Club Name"

examples/ClubMembers/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<link
1010
rel="stylesheet"
11-
href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.css"
11+
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.css"
1212
/>
1313
</head>
1414

examples/ClubMembers/style.css

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
1-
/* https://github.com/twbs/bootstrap/blob/v4.1.2/scss/_close.scss */
2-
button.close {
3-
float: initial;
4-
padding-left: 0.5rem;
5-
}
6-
7-
ul.list-none {
1+
.list-style-none {
82
list-style-type: none;
93
}
104

115
/*
12-
* https://github.com/twbs/bootstrap/blob/v4.1.2/scss/mixins/_forms.scss#L30
6+
* https://github.com/twbs/bootstrap/blob/v5.0.1/scss/mixins/_forms.scss#L26
137
*/
148
[data-feedback].error {
159
margin-top: 0.25rem; /* $form-feedback-margin-top => $form-text-margin-top => .25rem */
16-
font-size: 80%; /* $form-feedback-font-size => $small-font-size => 80% */
10+
font-size: 0.875em; /* $form-feedback-font-size => $form-text-font-size => $small-font-size => .875em */
1711
color: #dc3545; /* $form-feedback-invalid-color => $danger => $red => #dc3545 */
1812
}
1913
[data-feedback].warning {
2014
margin-top: 0.25rem;
21-
font-size: 80%;
15+
font-size: 0.875em;
2216
color: #ffc107; /* $warning => $yellow => #ffc107 */
2317
}
2418
[data-feedback].info {
2519
margin-top: 0.25rem;
26-
font-size: 80%;
27-
color: #17a2b8; /* $info => $cyan => #17a2b8 */
20+
font-size: 0.875em;
21+
color: #0dcaf0; /* $info => $cyan => #0dcaf0 */
2822
}
2923
[data-feedback].when-valid {
3024
margin-top: 0.25rem;
31-
font-size: 80%;
32-
color: #28a745; /* $form-feedback-valid-color => $success => $green => #28a745 */
25+
font-size: 0.875em;
26+
color: #198754; /* $form-feedback-valid-color => $success => $green => #198754 */
3327
}

packages/react-form-with-constraints-bootstrap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"test:coverage": "jest --coverage"
4141
},
4242
"peerDependencies": {
43-
"react-form-with-constraints": "^0.17.0"
43+
"react-form-with-constraints": ">=0.17.0"
4444
},
4545
"devDependencies": {
4646
"@types/enzyme": "^3.10.7",
Lines changed: 14 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,15 @@
1-
// Bootstrap 4 likes to hide feedbacks, we don't like it, especially react-form-with-constraints-tools's DisplayFields
2-
// [.invalid-feedback doesn't show for .input-group with an invalid control](https://github.com/twbs/bootstrap/issues/23454)
3-
.valid-feedback,
4-
.invalid-feedback {
5-
// stylelint-disable-next-line declaration-no-important
6-
display: block !important; // [Is there an opposite to display:none?](https://stackoverflow.com/a/37289654/990356)
7-
}
8-
9-
// stylelint-disable max-nesting-depth
10-
11-
// [v4-beta form-validation-state() mixin does not work](https://github.com/twbs/bootstrap/issues/23371)
12-
// [Fix form-validation-state() for unknown pseudo classes](https://github.com/twbs/bootstrap/pull/27409)
13-
// [ability to generate warning form state](https://github.com/twbs/bootstrap/pull/26471)
14-
// Taken and adapted from https://github.com/twbs/bootstrap/blob/v4.1.3/scss/mixins/_forms.scss#L29
15-
// Commented lines: 'display: none' + '.was-validated &:#{$state}'
16-
@mixin form-validation-state2($state, $color) {
17-
.#{$state}-feedback {
18-
//display: none;
19-
width: 100%;
20-
margin-top: $form-feedback-margin-top;
21-
font-size: $form-feedback-font-size;
22-
color: $color;
23-
}
24-
25-
.#{$state}-tooltip {
26-
position: absolute;
27-
top: 100%;
28-
z-index: 5;
29-
display: none;
30-
max-width: 100%; // Contain to parent when possible
31-
padding: $tooltip-padding-y $tooltip-padding-x;
32-
margin-top: 0.1rem;
33-
font-size: $tooltip-font-size;
34-
line-height: $line-height-base;
35-
color: color-yiq($color);
36-
background-color: rgba($color, $tooltip-opacity);
37-
@include border-radius($tooltip-border-radius);
38-
}
39-
40-
.form-control,
41-
.custom-select {
42-
//.was-validated &:#{$state},
43-
&.is-#{$state} {
44-
border-color: $color;
45-
46-
&:focus {
47-
border-color: $color;
48-
box-shadow: 0 0 0 $input-focus-width rgba($color, 0.25);
49-
}
50-
51-
~ .#{$state}-feedback,
52-
~ .#{$state}-tooltip {
53-
display: block;
54-
}
55-
}
56-
}
57-
58-
.form-control-file {
59-
//.was-validated &:#{$state},
60-
&.is-#{$state} {
61-
~ .#{$state}-feedback,
62-
~ .#{$state}-tooltip {
63-
display: block;
64-
}
65-
}
66-
}
67-
68-
.form-check-input {
69-
//.was-validated &:#{$state},
70-
&.is-#{$state} {
71-
~ .form-check-label {
72-
color: $color;
73-
}
74-
75-
~ .#{$state}-feedback,
76-
~ .#{$state}-tooltip {
77-
display: block;
78-
}
79-
}
80-
}
81-
82-
.custom-control-input {
83-
//.was-validated &:#{$state},
84-
&.is-#{$state} {
85-
~ .custom-control-label {
86-
color: $color;
87-
88-
&::before {
89-
background-color: lighten($color, 25%);
90-
}
91-
}
92-
93-
~ .#{$state}-feedback,
94-
~ .#{$state}-tooltip {
95-
display: block;
96-
}
97-
98-
&:checked {
99-
~ .custom-control-label::before {
100-
@include gradient-bg(lighten($color, 10%));
101-
}
102-
}
103-
104-
&:focus {
105-
~ .custom-control-label::before {
106-
box-shadow: 0 0 0 1px $body-bg, 0 0 0 $input-focus-width rgba($color, 0.25);
107-
}
108-
}
109-
}
110-
}
111-
112-
// custom file
113-
.custom-file-input {
114-
//.was-validated &:#{$state},
115-
&.is-#{$state} {
116-
~ .custom-file-label {
117-
border-color: $color;
118-
119-
&::after {
120-
border-color: inherit;
121-
}
122-
}
123-
124-
~ .#{$state}-feedback,
125-
~ .#{$state}-tooltip {
126-
display: block;
127-
}
128-
129-
&:focus {
130-
~ .custom-file-label {
131-
box-shadow: 0 0 0 $input-focus-width rgba($color, 0.25);
132-
}
133-
}
134-
}
135-
}
136-
}
137-
138-
// https://github.com/twbs/bootstrap/blob/v4.1.3/scss/_variables.scss#L572
139-
// $form-feedback-valid-color => $success => $green => #28a745
140-
// $form-feedback-invalid-color => $danger => $red => #dc3545
141-
$form-feedback-warning-color: theme-color('warning') !default; // $yellow => #ffc107
142-
$form-feedback-info-color: theme-color('info') !default; // $cyan => #17a2b8
143-
144-
// https://github.com/twbs/bootstrap/blob/v4.1.3/scss/_forms.scss#L243
1+
// FIXME Bootstrap 5.0.1 form-validation-state mixin needs an icon
2+
// We should submit a PR to remove this requirement
3+
$empty-icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>");
4+
5+
// https://github.com/twbs/bootstrap/blob/v5.0.1/scss/_variables.scss#L884-L893
6+
// https://github.com/twbs/bootstrap/blob/v5.0.1/scss/mixins/_forms.scss#L18
7+
@include form-validation-state('info', $info, $empty-icon);
8+
@include form-validation-state('warning', $warning, $empty-icon);
1459
// The order matters: invalid should be the last to override the other CSS rules
146-
// @include form-validation-state("valid", $form-feedback-valid-color);
147-
// @include form-validation-state("invalid", $form-feedback-invalid-color);
148-
@include form-validation-state2('info', $form-feedback-info-color);
149-
@include form-validation-state2('warning', $form-feedback-warning-color);
150-
@include form-validation-state2('valid', $form-feedback-valid-color);
151-
@include form-validation-state2('invalid', $form-feedback-invalid-color);
10+
@include form-validation-state('valid', $form-feedback-valid-color, $form-feedback-icon-valid);
11+
@include form-validation-state(
12+
'invalid',
13+
$form-feedback-invalid-color,
14+
$form-feedback-icon-invalid
15+
);

0 commit comments

Comments
 (0)