UNPKG

11.2 kBSCSSView Raw
1//
2// Copyright IBM Corp. 2016, 2018
3//
4// This source code is licensed under the Apache-2.0 license found in the
5// LICENSE file in the root directory of this source tree.
6//
7
8@import '../../globals/scss/helper-mixins';
9@import '../../globals/scss/vendor/@carbon/elements/scss/import-once/import-once';
10@import '../../globals/scss/layer';
11@import '../../globals/scss/layout';
12@import '../../globals/scss/vars';
13
14@mixin assistive-text {
15 position: absolute;
16 width: 1px;
17 height: 1px;
18 padding: 0;
19 margin: -1px;
20 overflow: hidden;
21 clip: rect(0, 0, 0, 0);
22 border: 0;
23 visibility: visible;
24 white-space: nowrap;
25}
26
27@include exports('data-table-v2-inline-edit-cell') {
28 // Spacing for cells that are the first in their row
29 $spacing--columns--first: 1.5rem;
30 // Spacing before columns in cell
31 $spacing--columns--before: 0.75rem;
32 // Spacing for activity areas in a cell, namely status and actions
33 $spacing--cell--activity: 3.5rem;
34 // Offset used on input nodes to offer space to activity indicators such that
35 // the input doesn't overlap with the status
36 $spacing--cell--status: 2rem;
37
38 //----------------------------------------------------------------------------
39 // Table
40 //----------------------------------------------------------------------------
41
42 // Reset hover styles while editing
43 .#{$prefix}--data-table--editing tr:hover td {
44 background-color: inherit;
45 border-top: 1px solid $ui-04;
46 border-bottom: 1px solid $ui-04;
47 }
48
49 .#{$prefix}--data-table--editing tr:hover td:first-of-type {
50 border-left: 1px solid $ui-04;
51 }
52
53 .#{$prefix}--data-table--editing tr:hover td:last-of-type {
54 border-right: 1px solid $ui-04;
55 }
56
57 //----------------------------------------------------------------------------
58 // Cell Edit
59 //----------------------------------------------------------------------------
60
61 // Buffer is created on the right-hand side so that status indicators have the
62 // appropriate space to display.
63 .#{$prefix}--data-table-cell--editable {
64 position: relative;
65 padding-right: $spacing--cell--activity;
66 }
67
68 td.#{$prefix}--data-table-cell--editable:last-of-type {
69 // Reset the styles inherited from data-table-v2 for padding-right styles
70 // but adding our manual offset plus the spacing used before columns to get
71 // a similar look for when an editable cell is in the middle of a table.
72 padding-right: #{$spacing--cell--activity + $spacing--columns--before};
73 }
74
75 // Minor offset for the last cell in a row so that the action bar does not
76 // touch the edge of the cell
77 td.#{$prefix}--data-table-cell--editable:last-of-type > .#{$prefix}--data-table-cell__activity {
78 margin-right: $spacing--columns--before;
79 }
80
81 //----------------------------------------------------------------------------
82 // Cell Edit - Content
83 //----------------------------------------------------------------------------
84 .#{$prefix}--data-table-cell__content {
85 position: relative;
86 z-index: 1000;
87 // Set line-height to match that within inputs
88 line-height: normal;
89 }
90
91 //----------------------------------------------------------------------------
92 // Cell Edit - Activity
93 //----------------------------------------------------------------------------
94
95 // Styles used for getting 100% width and height on an descendant of a table
96 // cell. Display is used for alignment of most items to the end of the cell
97 .#{$prefix}--data-table-cell__activity {
98 display: flex;
99 justify-content: flex-end;
100 align-items: center;
101 position: absolute;
102 top: 0;
103 right: 1rem;
104 bottom: 0;
105 left: 0;
106 }
107
108 //----------------------------------------------------------------------------
109 // Cell Edit - Trigger
110 //----------------------------------------------------------------------------
111
112 .#{$prefix}--data-table-cell__edit {
113 @include button-reset(false);
114 opacity: 0;
115 }
116
117 .#{$prefix}--data-table-cell__edit:focus,
118 .#{$prefix}--data-table-cell--editable:hover .#{$prefix}--data-table-cell__edit {
119 opacity: 1;
120 }
121
122 .#{$prefix}--data-table-cell__icon--edit {
123 fill: $ui-05;
124 }
125
126 .#{$prefix}--data-table-cell__edit:active > .#{$prefix}--data-table-cell__icon--edit {
127 fill: $brand-01;
128 }
129
130 .#{$prefix}--data-table-cell__edit:focus {
131 outline: 1px solid $brand-01;
132 outline-offset: 2px;
133 }
134
135 //----------------------------------------------------------------------------
136 // Cell Edit - Fields // Inputs
137 //----------------------------------------------------------------------------
138
139 .#{$prefix}--data-table__edit-field {
140 display: flex;
141 justify-content: flex-end;
142 align-items: center;
143 position: absolute;
144 top: 0;
145 right: 0;
146 bottom: 0;
147 left: 0;
148 z-index: 100;
149 }
150
151 .#{$prefix}--data-table__edit-field > label.#{$prefix}--label {
152 @include assistive-text();
153 }
154
155 // Spacing resets on inputs
156
157 // All inputs should span as much height and width as possible, but should
158 // still buffer the right hand side with some padding to allow space for
159 // status indicators to render without clipping the input content
160 .#{$prefix}--data-table__edit-field > input {
161 min-height: 100%;
162 min-width: 100%;
163 padding: 0 $spacing--cell--status 0 0;
164 }
165
166 // Set the default padding on the left-hand side of the input to match what is
167 // given by the default table class. Visually this makes it look like the
168 // content is aligned with the other cells in the table.
169 td.#{$prefix}--data-table-cell--editable input {
170 padding-left: $spacing--columns--before;
171 }
172
173 // Substitute the left-hand padding for the padding specified on the first td
174 // of each row
175 td.#{$prefix}--data-table-cell--editable:first-of-type input {
176 padding-left: $spacing--columns--first;
177 }
178
179 //----------------------------------------------------------------------------
180 // Cell Edit - Actions
181 //----------------------------------------------------------------------------
182
183 // Spacing that should exist around, and in-between, elements in the action
184 // bar
185 $spacing--cell-actions: 0.5rem;
186 $size--edit-actions--height: 3rem;
187
188 .#{$prefix}--data-table__edit-actions {
189 @include layer('overlay');
190
191 display: flex;
192 justify-content: flex-end;
193 align-items: center;
194 position: absolute;
195 top: $size--edit-actions--height;
196 right: 0;
197 bottom: 0;
198 height: $size--edit-actions--height;
199 background-color: $inverse-01;
200 padding: $spacing--cell-actions;
201 z-index: z('overlay');
202 }
203
204 // Undo default margin-left from btn classes
205 .#{$prefix}--data-table__edit-actions .#{$prefix}--btn--secondary + .#{$prefix}--btn--primary {
206 margin-left: $spacing--cell-actions;
207 }
208
209 //----------------------------------------------------------------------------
210 // Cell Edit - Status
211 //----------------------------------------------------------------------------
212
213 // Containing node
214 .#{$prefix}--data-table__edit-status {
215 display: flex;
216 justify-content: flex-end;
217 align-items: center;
218 position: absolute;
219 top: 0;
220 // Value should be 0.5rem, but doing so will cause the loading box to clip
221 // the bounding box of the last cells in a row. This will cause the
222 // overflow-x scrollbar to behave erratically as it constantly shifts to
223 // adjust to the new width of the table
224 right: 1rem;
225 bottom: 0;
226 left: 0;
227 }
228
229 // Status - Saving -----------------------------------------------------------
230
231 .#{$prefix}--data-table-cell--saving {
232 cursor: not-allowed;
233 }
234
235 // Cell should go to 25% opacity when saving
236 .#{$prefix}--data-table-cell--saving input {
237 background-color: inherit;
238 opacity: 0.25;
239 }
240
241 // Manually center the loading indicator given the offset of its bounding box
242 .#{$prefix}--data-table-cell--saving .#{$prefix}--loading {
243 position: relative;
244 left: rem(7px);
245 }
246
247 // Status - Success ----------------------------------------------------------
248 .#{$prefix}--data-table__icon--success {
249 fill: $support-02;
250 }
251
252 // Status - Error ------------------------------------------------------------
253
254 .#{$prefix}--data-table__status--error {
255 display: flex;
256 justify-content: flex-end;
257 align-items: center;
258 fill: $support-01;
259 width: 100%;
260 height: 100%;
261 }
262
263 .#{$prefix}--data-table__edit-field--error {
264 border-bottom: 2px solid $support-01;
265 }
266
267 .#{$prefix}--data-table__status--error {
268 position: relative;
269 }
270
271 .#{$prefix}--data-table__error-text {
272 @include layer('overlay');
273
274 position: absolute;
275 top: rem(-1px);
276 right: -1rem;
277 color: $support-01;
278 // TODO: sync with caption sizes
279 font-size: rem(12px);
280 background-color: $inverse-01;
281 padding: 1rem;
282 transform: translateY(-100%);
283 border: 1px solid $ui-03;
284 z-index: 1000;
285 box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.1);
286 opacity: 0;
287 }
288
289 .#{$prefix}--data-table__error-text::after {
290 content: '';
291 position: absolute;
292 // Manually offset and center triangle
293 right: 1rem;
294 // TODO: shift down half of height
295 bottom: -7px;
296 width: rem(10px);
297 height: rem(10px);
298 background-color: $inverse-01;
299 border: 1px solid $ui-03;
300 border-top: 1px solid transparent;
301 border-left: 1px solid transparent;
302 transform: rotate(45deg);
303 z-index: 10;
304 opacity: 0;
305 }
306
307 .#{$prefix}--data-table__icon--error {
308 z-index: 1000;
309 }
310
311 .#{$prefix}--data-table__status--error {
312 // Specify outline on child SVG node instead
313 outline: none;
314 }
315
316 .#{$prefix}--data-table__status--error:focus .#{$prefix}--data-table__error-text {
317 box-shadow: 0 0 0 1px $brand-01;
318 }
319
320 .#{$prefix}--data-table__status--error:focus .#{$prefix}--data-table__error-text::after {
321 border-right-color: $brand-01;
322 border-bottom-color: $brand-01;
323 }
324
325 // Visually show the error message
326
327 // Display the text area itself on hover
328 .#{$prefix}--data-table__icon--error:hover
329 ~ .#{$prefix}--data-table__error-text,
330
331 /* Display text area triangle on hover*/
332 .#{$prefix}--data-table__icon--error:hover
333 ~ .#{$prefix}--data-table__error-text::after,
334
335 /* Display text area on focus*/
336 .#{$prefix}--data-table__status--error:focus
337 > .#{$prefix}--data-table__error-text,
338
339 /* Display text area triangle on focus*/
340 .#{$prefix}--data-table__status--error:focus
341 > .#{$prefix}--data-table__error-text::after,
342
343 /* Display when user is typing in edit field*/
344 .#{$prefix}--data-table__edit-field--editing.#{$prefix}--data-table__edit-field--error +
345 .#{$prefix}--data-table__edit-status .#{$prefix}--data-table__error-text,
346
347 .#{$prefix}--data-table__edit-field--editing.#{$prefix}--data-table__edit-field--error +
348 .#{$prefix}--data-table__edit-status
349 .#{$prefix}--data-table__error-text::after {
350 opacity: 1;
351 }
352
353 //----------------------------------------------------------------------------
354 // Browser Quirks
355 //----------------------------------------------------------------------------
356
357 // IE11 - cells are not going full height. Set min-height to compensate
358 .#{$prefix}--data-table__edit-field,
359 .#{$prefix}--data-table-cell__activity,
360 .#{$prefix}--data-table__edit-status {
361 min-height: 3rem;
362 }
363}