@1024pix/pix-ui 62.0.0 → 62.1.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.
@@ -10,6 +10,7 @@ import PixBlock from './pix-block';
10
10
  export default class PixTable extends Component {
11
11
  get variant() {
12
12
  const value = this.args.variant ?? 'primary';
13
+
13
14
  warn(
14
15
  `PixTable: @variant "${value}" should be ${VARIANTS.join(', ')}`,
15
16
  VARIANTS.includes(value),
@@ -25,11 +26,11 @@ export default class PixTable extends Component {
25
26
  warn(`PixTable: @caption is required`, Boolean(this.args.caption), {
26
27
  id: 'pix-ui.pix-table.caption.required',
27
28
  });
29
+
28
30
  return this.args.caption;
29
31
  }
30
32
 
31
33
  get tableClass() {
32
- const tableClass = ['pix-table'];
33
34
  warn(
34
35
  'PixTable: @condensed must be a boolean, default undefined',
35
36
  [true, false, undefined].includes(this.args.condensed),
@@ -37,15 +38,14 @@ export default class PixTable extends Component {
37
38
  id: 'pix-ui.pix-table.condensed.not-boolean',
38
39
  },
39
40
  );
40
- if (this.args.condensed) {
41
- tableClass.push('pix-table--condensed');
42
- }
43
41
 
42
+ const tableClass = ['pix-table'];
43
+ if (this.args.condensed) tableClass.push('pix-table--condensed');
44
44
  return tableClass.join(' ');
45
45
  }
46
46
 
47
47
  get headerClass() {
48
- return `pix-table-header--${this.variant}`;
48
+ return `pix-table-header pix-table-header--${this.variant}`;
49
49
  }
50
50
 
51
51
  get captionClass() {
@@ -59,6 +59,7 @@ export default class PixTable extends Component {
59
59
  @action
60
60
  onClick(row, event) {
61
61
  event.stopPropagation();
62
+
62
63
  if (this.hasOnRowClick) {
63
64
  this.args.onRowClick(row);
64
65
  }
@@ -0,0 +1,82 @@
1
+ import { warn } from '@ember/debug';
2
+ import { on } from '@ember/modifier';
3
+ import { action } from '@ember/object';
4
+ import { guidFor } from '@ember/object/internals';
5
+ import Component from '@glimmer/component';
6
+ import { eq } from 'ember-truth-helpers';
7
+
8
+ import PixIcon from './pix-icon';
9
+ import PixLabel from './pix-label';
10
+
11
+ export default class PixToggle extends Component {
12
+ get id() {
13
+ return this.args.id || guidFor(this);
14
+ }
15
+
16
+ get cssClasses() {
17
+ const classes = ['pix-toggle'];
18
+
19
+ if (this.args.size) {
20
+ classes.push(`${classes[0]}--${this.args.size}`);
21
+ }
22
+
23
+ if (this.args.class) {
24
+ classes.push(this.args.class);
25
+ }
26
+
27
+ return classes.join(' ');
28
+ }
29
+
30
+ get isDisabled() {
31
+ warn(
32
+ 'PixToggle: @isDisabled attribute should be a boolean.',
33
+ [true, false, undefined, null].includes(this.args.isDisabled),
34
+ {
35
+ id: 'pix-ui.toggle.is-disabled.not-boolean',
36
+ },
37
+ );
38
+
39
+ return this.args.isDisabled ? 'true' : null;
40
+ }
41
+
42
+ @action
43
+ avoidCheckedStateChangeIfIsDisabled(event) {
44
+ if (this.isDisabled) {
45
+ event.preventDefault();
46
+ }
47
+ }
48
+
49
+ <template>
50
+ <PixLabel
51
+ class={{this.cssClasses}}
52
+ for={{this.id}}
53
+ @size={{if (eq @size "large") "large" "small"}}
54
+ @inlineLabel={{true}}
55
+ @isDisabled={{this.isDisabled}}
56
+ >
57
+ {{#if (has-block)}}
58
+ <span class="pix-toggle__label">
59
+ {{yield}}
60
+ </span>
61
+ {{/if}}
62
+ <span class="pix-toggle__input">
63
+ {{! template-lint-disable require-mandatory-role-attributes }}
64
+ {{! Native checkbox checkedness conveys the switch state; aria-checked would be redundant and unreliable }}
65
+ <input
66
+ class="pix-toggle-input__checkbox"
67
+ role="switch"
68
+ type="checkbox"
69
+ id={{this.id}}
70
+ checked={{@checked}}
71
+ aria-disabled={{this.isDisabled}}
72
+ {{on "click" this.avoidCheckedStateChangeIfIsDisabled}}
73
+ ...attributes
74
+ />
75
+ <span class="pix-toggle-input__thumb">
76
+ <PixIcon class="pix-toggle-input__icon--checked" @name="check" @ariaHidden={{true}} />
77
+ <PixIcon class="pix-toggle-input__icon--unchecked" @name="close" @ariaHidden={{true}} />
78
+ </span>
79
+ </span>
80
+ </PixLabel>
81
+ </template>
82
+ }
@@ -2,6 +2,8 @@
2
2
  @use "pix-design-tokens/typography";
3
3
 
4
4
  .pix-table {
5
+ @extend %pix-body-s;
6
+
5
7
  min-width: 100%;
6
8
  overflow: auto;
7
9
 
@@ -9,106 +11,100 @@
9
11
  overflow: unset;
10
12
  }
11
13
 
12
- @extend %pix-body-s;
13
-
14
- &__caption {
15
- margin-bottom: var(--pix-spacing-3x);
16
- text-align: left;
17
- caption-side: top;
14
+ table {
15
+ width: 100%;
16
+ border-collapse: collapse;
17
+ }
18
18
 
19
- @extend %pix-title-xxs;
19
+ tbody > tr:nth-of-type(even) > :is(td, th) {
20
+ background-color: rgba(var(--pix-neutral-20-inline), 0.80);
20
21
  }
21
22
 
22
- &__clickable-row {
23
+ tbody > tr.pix-table__clickable-row {
23
24
  cursor: pointer;
24
25
 
25
- &:hover, &:focus, &:active {
26
- transition: 0.25s ease;
26
+ & > :is(td, th) {
27
+ transition: background-color 0.25s ease;
27
28
  }
28
29
 
29
- &:hover {
30
+ &:hover > :is(td, th) {
30
31
  background-color: rgba(var(--pix-neutral-100-inline), 0.50);
31
32
  }
32
33
 
33
- &:focus {
34
+ &:focus > :is(td, th) {
34
35
  background-color: rgba(var(--pix-neutral-100-inline), 0.40);
35
36
  }
36
37
 
37
- &:active {
38
+ &:active > :is(td, th) {
38
39
  background-color: rgba(var(--pix-neutral-100-inline), 0.75);
39
40
  }
40
41
  }
41
42
 
42
- table {
43
- width: 100%;
44
- border-collapse: collapse;
45
- }
46
-
47
- tbody > tr:nth-of-type(even):not(.pix-table__clickable-row:hover, .pix-table__clickable-row:focus, .pix-table__clickable-row:active) {
48
- background-color: rgba(var(--pix-neutral-20-inline), 0.80);
49
- }
50
-
51
- thead.pix-table-header {
52
- &--primary {
53
- background: var(--pix-primary-10);
54
- }
55
-
56
- &--orga {
57
- background: var(--pix-orga-50);
58
- }
59
-
60
- &--certif {
61
- background: var(--pix-certif-50);
62
- }
63
-
64
- &--admin {
65
- background: var(--pix-primary-100);
66
- }
67
- }
43
+ td, th {
44
+ padding: var(--pix-spacing-4x);
68
45
 
69
- .pix-table-header-container {
70
- display: flex;
71
- gap: var(--pix-spacing-1x);
72
- align-items: center;
46
+ &:first-child {
47
+ border-top-left-radius: var(--pix-spacing-2x);
48
+ border-bottom-left-radius: var(--pix-spacing-2x);
73
49
  }
74
50
 
75
- th[scope='col'] {
76
- font-weight: var(--pix-font-bold);
77
- text-align: start;
78
- vertical-align: middle;
51
+ &:last-child {
52
+ border-top-right-radius: var(--pix-spacing-2x);
53
+ border-bottom-right-radius: var(--pix-spacing-2x);
79
54
  }
55
+ }
56
+ }
80
57
 
81
- th[scope='row'] {
82
- font-weight: var(--pix-font-normal);
83
- }
58
+ .pix-table--condensed {
59
+ th, td {
60
+ padding: var(--pix-spacing-2x) var(--pix-spacing-4x);
61
+ }
84
62
 
63
+ td.pix-table-column--tag,
64
+ td.pix-table-column--link {
65
+ padding-top: 0.375rem;
66
+ padding-bottom: 0.375rem;
67
+ }
68
+ }
85
69
 
86
- td, th {
87
- padding: var(--pix-spacing-4x) var(--pix-spacing-4x);
70
+ .pix-table-header {
71
+ &--primary th {
72
+ background: var(--pix-primary-10);
73
+ }
88
74
 
89
- &:first-child {
90
- border-radius: var(--pix-spacing-2x) 0 0 var(--pix-spacing-2x);
91
- }
75
+ &--orga th {
76
+ background: var(--pix-orga-50);
77
+ }
92
78
 
93
- &:last-child {
94
- border-radius: 0 var(--pix-spacing-2x) var(--pix-spacing-2x) 0;
95
- }
96
- }
79
+ &--certif th {
80
+ background: var(--pix-certif-50);
81
+ }
97
82
 
98
- &--condensed {
99
- th, td {
100
- padding: .5rem var(--pix-spacing-4x);
101
- }
83
+ &--admin th {
84
+ background: var(--pix-primary-100);
85
+ }
102
86
 
103
- td.pix-table-column--tag {
104
- padding-top: 0.375rem;
105
- padding-bottom: 0.375rem;
106
- }
87
+ th[scope='col'] {
88
+ font-weight: var(--pix-font-bold);
89
+ text-align: start;
90
+ vertical-align: middle;
91
+ }
107
92
 
108
- td.pix-table-column--link {
109
- padding-top: 0.375rem;
110
- padding-bottom: 0.375rem;
111
- }
93
+ th[scope='row'] {
94
+ font-weight: var(--pix-font-normal);
112
95
  }
113
96
  }
114
97
 
98
+ .pix-table-header-container {
99
+ display: flex;
100
+ gap: var(--pix-spacing-1x);
101
+ align-items: center;
102
+ }
103
+
104
+ .pix-table__caption {
105
+ margin-bottom: var(--pix-spacing-3x);
106
+ text-align: left;
107
+ caption-side: top;
108
+
109
+ @extend %pix-title-xxs;
110
+ }
@@ -0,0 +1,107 @@
1
+ .pix-toggle {
2
+ --thumb-width: 1rem;
3
+
4
+ display: inline-block;
5
+ cursor: pointer;
6
+
7
+ &--large {
8
+ --thumb-width: 1.375rem;
9
+ }
10
+
11
+ &:has(:disabled),
12
+ &:has([aria-disabled='true']) {
13
+ cursor: not-allowed;
14
+ }
15
+ }
16
+
17
+ .pix-toggle__label {
18
+ margin-right: var(--pix-spacing-4x);
19
+ font-weight: var(--pix-font-bold);
20
+ vertical-align: middle;
21
+ }
22
+
23
+ .pix-toggle__input {
24
+ position: relative;
25
+ display: inline-block;
26
+ width: calc(var(--thumb-width) * 2.375);
27
+ color: var(--pix-neutral-500);
28
+ vertical-align: middle;
29
+ background-color: currentcolor;
30
+ border: 2px solid currentcolor;
31
+ border-radius: 5rem;
32
+ outline: 1px solid transparent;
33
+ transition: outline-color 0.2s ease-in-out, background-color 0.2s ease-in-out;
34
+
35
+ &:has(:checked) {
36
+ color: var(--pix-primary-500);
37
+
38
+ .pix-toggle-input__thumb {
39
+ transform: translateX(calc(137.5% - 4px));
40
+ }
41
+
42
+ .pix-toggle-input__icon--checked {
43
+ display: block;
44
+ }
45
+
46
+ .pix-toggle-input__icon--unchecked {
47
+ display: none;
48
+ }
49
+ }
50
+
51
+ &:not(:has(:disabled), :has([aria-disabled='true'])) {
52
+ &:hover,
53
+ &:has(:focus) {
54
+ color: var(--pix-neutral-800);
55
+ }
56
+
57
+ &:has(:checked):hover,
58
+ &:has(:checked):has(:focus) {
59
+ color: var(--pix-primary-700);
60
+ }
61
+ }
62
+
63
+ &:has(:focus) {
64
+ outline-color: currentcolor;
65
+ outline-offset: 1px;
66
+ }
67
+
68
+ // Disabled state
69
+ &:has(:disabled),
70
+ &:has([aria-disabled='true']) {
71
+ color: var(--pix-neutral-100);
72
+
73
+ &:has(:checked) {
74
+ color: var(--pix-primary-300);
75
+ }
76
+
77
+ &:has(:focus) {
78
+ outline-color: var(--pix-neutral-800);
79
+ }
80
+ }
81
+ }
82
+
83
+ .pix-toggle-input__checkbox {
84
+ position: absolute;
85
+ cursor: pointer;
86
+ opacity: 0;
87
+ inset: 0;
88
+ }
89
+
90
+ .pix-toggle-input__thumb {
91
+ display: flex;
92
+ align-items: center;
93
+ justify-content: center;
94
+ width: var(--thumb-width);
95
+ height: var(--thumb-width);
96
+ background-color: var(--pix-neutral-0);
97
+ border-radius: 50%;
98
+ transition: transform 0.2s ease-in-out;
99
+
100
+ svg {
101
+ transform: scale(0.8);
102
+ }
103
+ }
104
+
105
+ .pix-toggle-input__icon--checked {
106
+ display: none;
107
+ }
@@ -54,6 +54,7 @@
54
54
  @use 'pix-stepper';
55
55
  @use 'pix-card';
56
56
  @use 'pix-accordions-v2';
57
+ @use 'pix-toggle';
57
58
 
58
59
  // at the end so it can override it's children scss
59
60
  @use 'pix-filterable-and-searchable-select';
@@ -0,0 +1 @@
1
+ export { default } from '@1024pix/pix-ui/components/pix-toggle';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1024pix/pix-ui",
3
- "version": "62.0.0",
3
+ "version": "62.1.0",
4
4
  "description": "Pix-UI is the implementation of Pix design principles and guidelines for its products.",
5
5
  "keywords": [
6
6
  "ember-addon"