@carbon/element-styles 0.3.1 → 0.3.2-rc.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/element-styles",
3
3
  "description": "An experimental styling system for native HTML elements, relying on semantic, attribute-focused selectors instead of class names.",
4
- "version": "0.3.1",
4
+ "version": "0.3.2-rc.0",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "sass": "index.scss",
@@ -6,6 +6,8 @@
6
6
  */
7
7
 
8
8
  @use 'sass:map';
9
+ @use 'sass:string';
10
+ @use 'sass:list';
9
11
 
10
12
  @use '@carbon/styles/scss/theme';
11
13
  @use '@carbon/styles/scss/spacing';
@@ -21,12 +23,14 @@ $config: () !default;
21
23
  $-default-config: (
22
24
  selector: '[popover]',
23
25
  caret: true,
26
+ alignment: 'end center',
24
27
  );
25
28
 
26
29
  /// @group popover
27
30
  /// @param {Map} config [()]
28
31
  /// @param {Selector} config.selector ['[popover]']
29
32
  /// @param {Bool} config.caret [true]
33
+ /// @param {'start start' | 'start center' | 'start end' | 'center start' | 'center end' | 'end start' | 'end center' | 'end end'} config.alignment ['end center']
30
34
  @mixin styles($config: $config) {
31
35
  $props: map.deep-merge($-default-config, $config);
32
36
 
@@ -39,11 +43,8 @@ $-default-config: (
39
43
  @include layer.styles;
40
44
  @include box-shadow.box-shadow;
41
45
  @include layout.mode--body;
42
- position: absolute;
43
- inset: unset;
44
46
  margin: 0;
45
- inset-block-start: calc(anchor(end) + spacing.$spacing-02 + ($-caret-size * 0.5));
46
- inset-inline-start: calc(anchor(start) + spacing.$spacing-02);
47
+ position: fixed;
47
48
  border: none;
48
49
  border-radius: 0.125rem;
49
50
  padding: layout.$density--padding;
@@ -56,10 +57,7 @@ $-default-config: (
56
57
  display: block;
57
58
  block-size: $-caret-size;
58
59
  inline-size: $-caret-size;
59
- rotate: -45deg;
60
60
  background-color: inherit;
61
- inset-block-start: calc($-caret-size * -0.5);
62
- inset-inline-start: layout.$density--padding;
63
61
  clip-path: polygon(
64
62
  0% 0%,
65
63
  100% 0%,
@@ -67,5 +65,87 @@ $-default-config: (
67
65
  0% 0%,
68
66
  );
69
67
  }
68
+
69
+ $-alignment: string.split(map.get($props, 'alignment'), " ");
70
+ $-alignment-block: list.nth($-alignment, 1);
71
+ $-alignment-inline: list.nth($-alignment, 2);
72
+
73
+ @if $-alignment-block == 'start' {
74
+ position-area: start center;
75
+ inset-block-end: calc(spacing.$spacing-02 + ($-caret-size * 0.5));
76
+
77
+ &::before {
78
+ inset-block-end: calc($-caret-size * -0.5);
79
+ rotate: 135deg;
80
+ }
81
+ }
82
+
83
+ @if $-alignment-block == 'end' {
84
+ position-area: end center;
85
+ inset-block-start: calc(spacing.$spacing-02 + ($-caret-size * 0.5));
86
+
87
+ &::before {
88
+ inset-block-start: calc($-caret-size * -0.5);
89
+ rotate: -45deg;
90
+ }
91
+ }
92
+
93
+ @if $-alignment-block == 'start' or $-alignment-block == 'end' {
94
+ @if $-alignment-inline == 'start' {
95
+ translate: calc(-50% + layout.$density--padding + spacing.$spacing-02) 0;
96
+
97
+ &::before {
98
+ inset-inline-start: -get-caret-offset('end', $-caret-size);
99
+ }
100
+ } @else if $-alignment-inline == 'end' {
101
+ translate: calc(50% - layout.$density--padding - spacing.$spacing-02) 0;
102
+
103
+ &::before {
104
+ inset-inline-start: -get-caret-offset('start', $-caret-size);
105
+ }
106
+ } @else if $-alignment-inline == 'center' {
107
+ &::before {
108
+ inset-inline-start: -get-caret-offset('center', $-caret-size);
109
+ }
110
+ }
111
+ }
112
+
113
+ @if map.get($props, 'alignment') == 'center start' {
114
+ position-area: center start;
115
+ translate: calc((spacing.$spacing-02 + ($-caret-size * 0.5)) * -1);
116
+
117
+ &::before {
118
+ inset-block-start: -get-caret-offset('center', $-caret-size);
119
+ inset-inline-end: calc($-caret-size * -0.5);
120
+ rotate: 45deg;
121
+ }
122
+ }
123
+
124
+ @if map.get($props, 'alignment') == 'center end' {
125
+ position-area: center end;
126
+ translate: calc(spacing.$spacing-02 + ($-caret-size * 0.5));
127
+
128
+ &::before {
129
+ inset-block-start: -get-caret-offset('center', $-caret-size);
130
+ inset-inline-start: calc($-caret-size * -0.5);
131
+ rotate: -135deg;
132
+ }
133
+ }
134
+ }
135
+ }
136
+
137
+ @function -get-caret-offset($position, $caret-size: 0rem) {
138
+ @if ($position == 'start') {
139
+ @return calc(layout.$density--padding - $caret-size * 0.5 + spacing.$spacing-02);
140
+ }
141
+
142
+ @if ($position == 'center') {
143
+ @return calc(50% - $caret-size * 0.5);
70
144
  }
145
+
146
+ @if ($position == 'end') {
147
+ @return calc(100% - layout.$density--padding - $caret-size * 0.5 - spacing.$spacing-02);
148
+ }
149
+
150
+ @error '"#{$position}" is not one of "start" | "center" | "end"';
71
151
  }
@@ -17,11 +17,13 @@ $config: () !default;
17
17
 
18
18
  $-default-config: (
19
19
  selector: '[popover="hint"]',
20
+ alignment: 'start center',
20
21
  );
21
22
 
22
23
  /// @group tooltip
23
24
  /// @param {Map} config [()]
24
25
  /// @param {Selector} config.selector ['[popover="hint"]']
26
+ /// @param {'start start' | 'start center' | 'start end' | 'center start' | 'center end' | 'end start' | 'end center' | 'end end'} config.alignment ['start center']
25
27
  @mixin styles($config: $config) {
26
28
  $props: map.deep-merge($-default-config, $config);
27
29
 
@@ -29,16 +31,10 @@ $-default-config: (
29
31
  @include popover.styles((
30
32
  selector: '&',
31
33
  caret: true,
34
+ alignment: map.get($props, 'alignment'),
32
35
  ));
33
36
 
34
37
  background-color: theme.$background-inverse;
35
38
  color: theme.$text-inverse;
36
- justify-self: anchor-center;
37
- inset-inline: unset;
38
-
39
- &::before {
40
- inset-inline-start: 50%;
41
- translate: -50% 0;
42
- }
43
39
  }
44
40
  }