@ministryofjustice/frontend 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@
5
5
  @import "button-menu/button-menu";
6
6
  @import "cookie-banner/cookie-banner";
7
7
  @import "currency-input/currency-input";
8
+ @import "date-picker/date-picker";
8
9
  @import "filter/filter";
9
10
  @import "header/header";
10
11
  @import "identity-bar/identity-bar";
@@ -0,0 +1,36 @@
1
+ # Date picker
2
+
3
+ - [Guidance](https://design-patterns.service.justice.gov.uk/components/date-picker
4
+ picker)
5
+
6
+ ## Example
7
+
8
+ ```
9
+ {{ mojDatePicker({
10
+ id: "appointment-date",
11
+ name: "appointment-date"
12
+ label: "Appointment date"
13
+ hint: For example, 17/5/2024.
14
+ }) }}
15
+ ```
16
+
17
+ ## Arguments
18
+
19
+ This component accepts the following arguments.
20
+
21
+ | Name | Type | Required | Description |
22
+ | ------------ | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------- |
23
+ | id | string | Yes | The ID of the input. |
24
+ | name | string | Yes | The name of the input, which is submitted with the form data. |
25
+ | value | string | No | Optional initial value of the input. |
26
+ | formGroup | object | No | Additional options for the form group containing the text input component. See [formGroup](#options-date-picker-form-group). |
27
+ | label | object | Yes | The label used by the text input component. See [GOV.UK text input documentation](https://design-system.service.gov.uk/components/text-input/) for label options. |
28
+ | hint | object | No | Can be used to add a hint to a text input component. See [GOV.UK text input documentation](https://design-system.service.gov.uk/components/text-input/) for hint options. |
29
+ | errorMessage | object | No | Can be used to add an error message to the text input component. The error message component will not display if you use a falsy value for `errorMessage`, for example `false` or `null`. See [GOV.UK text input documentation](https://design-system.service.gov.uk/components/text-input/) for errorMessage options. |
30
+ | minDate | string | No | Earliest date that can be selected (format dd/mm/yyyy) |
31
+ | maxDate | string | No | Latest date that can be selected (format dd/mm/yyyy) |
32
+ | exludedDates | string | No | String of pace separated dates that cannot be selected |
33
+ | excludedDays | string | No | String of space separated days of the week that cannot be selected |
34
+ | weekStartDay | string | No | Day of the week the calendar starts on. Either 'monday' or 'sunday'. Defaults to 'monday' |
35
+
36
+
@@ -0,0 +1,293 @@
1
+ // Custom colour required for passing WCAG 2.2 AA contrast text/background and
2
+ // background/surrounding
3
+ $moj-datepicker-mid-grey: #949494;
4
+
5
+ .moj-datepicker {
6
+ position: relative;
7
+ @include govuk-font(16);
8
+ }
9
+
10
+ .moj-datepicker__dialog {
11
+ display: none;
12
+ position: absolute;
13
+ top: 0;
14
+ min-width: 280px;
15
+ padding: govuk-spacing(4);
16
+ outline: 2px solid $govuk-text-colour;
17
+ outline-offset: -2px;
18
+ background-color: govuk-colour('white');
19
+ transition: background-color 0.2s, outline-color 0.2s;
20
+ z-index: 2;
21
+ }
22
+
23
+ .moj-datepicker__dialog--open {
24
+ display: block;
25
+ }
26
+
27
+ .moj-datepicker__dialog-header {
28
+ position: relative;
29
+ display: flex;
30
+ align-items: center;
31
+ justify-content: space-between;
32
+ margin-bottom: govuk-spacing(2);
33
+ }
34
+
35
+ .moj-datepicker__dialog-title {
36
+ @include govuk-font(16);
37
+ font-weight: bold;
38
+ margin-top: 0;
39
+ margin-bottom: 0;
40
+ }
41
+
42
+ .moj-datepicker__dialog-navbuttons {
43
+ display: flex;
44
+ align-items: center;
45
+ }
46
+
47
+ .moj-datepicker__calendar {
48
+ border-collapse: collapse;
49
+ margin-bottom: govuk-spacing(4);
50
+
51
+ tbody:focus-within {
52
+ outline: 2px solid $govuk-focus-colour;
53
+ }
54
+
55
+ td {
56
+ border: 0;
57
+ margin: 0;
58
+ outline: 0;
59
+ padding: 0;
60
+ }
61
+
62
+ th {
63
+ @include govuk-font(16);
64
+ font-weight: bold;
65
+ color: $govuk-text-colour;
66
+ }
67
+
68
+ }
69
+
70
+ .moj-datepicker__dialog > .govuk-button-group {
71
+ margin-bottom: 0;
72
+
73
+ > * {
74
+ margin-bottom: 0;
75
+ }
76
+ }
77
+
78
+ .moj-datepicker__button {
79
+ @include govuk-font(16);
80
+ background-color: transparent;
81
+ outline: 2px solid rgba(0, 0, 0, 0);
82
+ outline-offset: -2px;
83
+ border-width: 0;
84
+ color: $govuk-text-colour;
85
+ height: 40px;
86
+ margin: 0;
87
+ padding: 0;
88
+ width: 44px;
89
+ position: relative;
90
+
91
+ @media (forced-colors: active) {
92
+ // Don't show the bottom bar in forced-color modes as it blocks the outline
93
+ &:after {
94
+ display: none
95
+ }
96
+ }
97
+
98
+ &:after {
99
+ content: "";
100
+ position: absolute;
101
+ bottom: 0px;
102
+ height: 4px;
103
+ left: 0;
104
+ right: 0;
105
+ background-color: transparent;
106
+ }
107
+
108
+ &[aria-disabled="true"],
109
+ &[aria-disabled="true"]:hover {
110
+ background-color: govuk-colour('light-grey');
111
+ color: $govuk-text-colour;
112
+ cursor: not-allowed;
113
+ text-decoration: line-through;
114
+ }
115
+
116
+ &:hover {
117
+ color: $govuk-text-colour;
118
+ background-color: $moj-datepicker-mid-grey;
119
+ text-decoration: none;
120
+ -webkit-box-decoration-break: clone;
121
+ box-decoration-break: clone;
122
+ cursor: pointer;
123
+ }
124
+
125
+ &:focus {
126
+ color: $govuk-text-colour;
127
+ background-color: $govuk-focus-colour;
128
+ outline-color: transparent;
129
+ -webkit-box-decoration-break: clone;
130
+ box-decoration-break: clone;
131
+ &:after {
132
+ background-color: $govuk-text-colour;
133
+ }
134
+ }
135
+
136
+ &:focus:hover {
137
+ background-color: $moj-datepicker-mid-grey;
138
+ outline-color: $govuk-focus-colour;
139
+ &:after {
140
+ background-color: transparent;
141
+ }
142
+ }
143
+
144
+ &--current:not(:focus) {
145
+ background-color: $govuk-link-colour;
146
+ color: govuk-colour('white');
147
+ outline-color: $govuk-link-colour;
148
+ &:after {
149
+ background-color: $govuk-link-colour;
150
+ }
151
+ }
152
+
153
+ &--current[tabindex="-1"] {
154
+ background: transparent;
155
+ color: currentColor;
156
+ outline-color: transparent;
157
+ &:after {
158
+ background-color: transparent;
159
+ }
160
+ }
161
+
162
+ &--today {
163
+ border: 2px solid $govuk-text-colour;
164
+ }
165
+
166
+ &--selected:not(:focus) {
167
+ background-color: $govuk-link-colour;
168
+ color: govuk-colour('white');
169
+
170
+ &:after {
171
+ background-color: $govuk-link-colour;
172
+ }
173
+
174
+ &:hover {
175
+ outline-color: $govuk-link-colour;
176
+ background-color: $moj-datepicker-mid-grey;
177
+ color: $govuk-text-colour;
178
+
179
+ &:after {
180
+ background-color: transparent;
181
+ }
182
+ }
183
+ }
184
+
185
+ }
186
+
187
+ /*
188
+ Default input with to .govuk-input--width-10 (10 chars)
189
+ Allow that to be overriden by the input width modifiers or global width overrides.
190
+ Width classes less than 10ch not included as that is narrower than a date.
191
+ */
192
+ .moj-datepicker input {
193
+ max-width: 11.5em; // govuk-input--width-10
194
+
195
+ &.govuk-input--width-30 {
196
+ max-width: 29.5em;
197
+ }
198
+
199
+ &.govuk-input--width-20 {
200
+ max-width: 20.5em;
201
+ }
202
+
203
+ &.govuk-\!-width-full {
204
+ width: 100% !important;
205
+ max-width: none;
206
+ }
207
+
208
+ &.govuk-\!-width-three-quarters {
209
+ width: 100% !important;
210
+ max-width: none;
211
+
212
+ @include govuk-media-query($from: tablet) {
213
+ width: 75% !important;
214
+ }
215
+ }
216
+
217
+ &.govuk-\!-width-two-thirds {
218
+ width: 100% !important;
219
+ max-width: none;
220
+
221
+ @include govuk-media-query($from: tablet) {
222
+ width: 66.66% !important;
223
+ }
224
+ }
225
+
226
+ &.govuk-\!-width-one-half {
227
+ width: 100% !important;
228
+ max-width: none;
229
+
230
+ @include govuk-media-query($from: tablet) {
231
+ width: 50% !important;
232
+ }
233
+ }
234
+
235
+ &.govuk-\!-width-one-third {
236
+ width: 100% !important;
237
+ max-width: none;
238
+
239
+ @include govuk-media-query($from: tablet) {
240
+ width: 33.33% !important;
241
+ }
242
+ }
243
+
244
+ &.govuk-\!-width-one-quarter {
245
+ width: 100% !important;
246
+ max-width: none;
247
+
248
+ @include govuk-media-query($from: tablet) {
249
+ width: 25% !important;
250
+ }
251
+ }
252
+ }
253
+
254
+ .moj-datepicker__wrapper {
255
+ position: relative;
256
+ }
257
+
258
+
259
+ @media (min-width: 768px) {
260
+ .moj-datepicker__dialog {
261
+ width: auto;
262
+ }
263
+ }
264
+
265
+ .moj-datepicker__toggle {
266
+ background-color: $govuk-text-colour;
267
+ color: govuk-colour('white');
268
+ outline: 3px solid rgba(0, 0, 0, 0);
269
+ outline-offset: -3px;
270
+ height: 40px;
271
+ padding-top: 6px;
272
+ border: none;
273
+ border-bottom: 4px solid rgba(0, 0, 0, 0);
274
+ cursor: pointer;
275
+
276
+ &:focus {
277
+ background-color: $govuk-focus-colour;
278
+ color: $govuk-text-colour;
279
+ border-bottom: 4px solid $govuk-text-colour;
280
+ }
281
+
282
+ &:hover {
283
+ background-color: $moj-datepicker-mid-grey;
284
+ color: $govuk-text-colour;
285
+ border-bottom: 4px solid $moj-datepicker-mid-grey;
286
+ }
287
+
288
+ &:focus:hover {
289
+ background-color: $moj-datepicker-mid-grey;
290
+ color: $govuk-text-colour;
291
+ border-bottom: 4px solid $govuk-text-colour;
292
+ }
293
+ }