primer_view_components 0.0.123 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -0
  3. data/app/assets/javascripts/primer_view_components.js +1 -1
  4. data/app/assets/javascripts/primer_view_components.js.map +1 -1
  5. data/app/assets/styles/primer_view_components.css +2 -2
  6. data/app/assets/styles/primer_view_components.css.map +1 -1
  7. data/app/components/primer/alpha/action_list/divider.rb +2 -2
  8. data/app/components/primer/alpha/action_list/heading.html.erb +1 -1
  9. data/app/components/primer/alpha/action_list/heading.rb +10 -4
  10. data/app/components/primer/alpha/action_list/item.rb +7 -3
  11. data/app/components/primer/alpha/action_list.css.json +41 -0
  12. data/app/components/primer/alpha/action_list.html.erb +6 -8
  13. data/app/components/primer/alpha/action_list.rb +5 -10
  14. data/app/components/primer/alpha/auto_complete.css.json +11 -0
  15. data/app/components/primer/alpha/banner.css.json +14 -0
  16. data/app/components/primer/alpha/button_marketing.css.json +10 -0
  17. data/app/components/primer/alpha/dialog.css.json +63 -0
  18. data/app/components/primer/alpha/dropdown.css.json +21 -0
  19. data/app/components/primer/alpha/layout.css.json +27 -0
  20. data/app/components/primer/alpha/menu.css.json +11 -0
  21. data/app/components/primer/alpha/nav_list/{section.rb → group.rb} +9 -9
  22. data/app/components/primer/alpha/nav_list/item.html.erb +1 -1
  23. data/app/components/primer/alpha/nav_list/item.rb +18 -2
  24. data/app/components/primer/alpha/nav_list.d.ts +1 -0
  25. data/app/components/primer/alpha/nav_list.html.erb +8 -8
  26. data/app/components/primer/alpha/nav_list.js +24 -0
  27. data/app/components/primer/alpha/nav_list.rb +28 -32
  28. data/app/components/primer/alpha/nav_list.ts +27 -0
  29. data/app/components/primer/alpha/navigation/tab.rb +168 -0
  30. data/app/components/primer/alpha/overlay/body.rb +26 -0
  31. data/app/components/primer/alpha/overlay/footer.rb +41 -0
  32. data/app/components/primer/alpha/overlay/header.html.erb +15 -0
  33. data/app/components/primer/alpha/overlay/header.rb +47 -0
  34. data/app/components/primer/alpha/overlay.css +1 -0
  35. data/app/components/primer/alpha/overlay.css.json +11 -0
  36. data/app/components/primer/alpha/overlay.css.map +1 -0
  37. data/app/components/primer/alpha/overlay.html.erb +11 -0
  38. data/app/components/primer/alpha/overlay.pcss +14 -0
  39. data/app/components/primer/alpha/overlay.rb +207 -0
  40. data/app/components/primer/alpha/segmented_control.css.json +15 -0
  41. data/app/components/primer/alpha/tab_nav.css.json +10 -0
  42. data/app/components/primer/alpha/tab_nav.rb +10 -3
  43. data/app/components/primer/alpha/tab_panels.rb +2 -2
  44. data/app/components/primer/alpha/text_field.css.json +38 -0
  45. data/app/components/primer/alpha/toggle_switch.css.json +16 -0
  46. data/app/components/primer/alpha/underline_nav.css +1 -1
  47. data/app/components/primer/alpha/underline_nav.css.json +13 -0
  48. data/app/components/primer/alpha/underline_nav.css.map +1 -1
  49. data/app/components/primer/alpha/underline_nav.pcss +1 -0
  50. data/app/components/primer/alpha/underline_nav.rb +2 -2
  51. data/app/components/primer/alpha/underline_panels.rb +2 -2
  52. data/app/components/primer/anchored_position.d.ts +27 -0
  53. data/app/components/primer/anchored_position.js +149 -0
  54. data/app/components/primer/anchored_position.ts +167 -0
  55. data/app/components/primer/beta/avatar.css.json +14 -0
  56. data/app/components/primer/beta/avatar_stack.css.json +9 -0
  57. data/app/components/primer/beta/blankslate.css.json +12 -0
  58. data/app/components/primer/beta/border_box.css.json +32 -0
  59. data/app/components/primer/beta/breadcrumbs.css.json +4 -0
  60. data/app/components/primer/beta/button.css.json +22 -0
  61. data/app/components/primer/beta/button.html.erb +1 -1
  62. data/app/components/primer/beta/button.rb +2 -1
  63. data/app/components/primer/beta/counter.css.json +6 -0
  64. data/app/components/primer/beta/flash.css.json +15 -0
  65. data/app/components/primer/beta/flash.html.erb +1 -2
  66. data/app/components/primer/beta/label.css.json +20 -0
  67. data/app/components/primer/beta/link.css.json +8 -0
  68. data/app/components/primer/beta/popover.css.json +18 -0
  69. data/app/components/primer/beta/progress_bar.css.json +6 -0
  70. data/app/components/primer/beta/state.css.json +10 -0
  71. data/app/components/primer/beta/subhead.css.json +8 -0
  72. data/app/components/primer/beta/timeline_item.css.json +9 -0
  73. data/app/components/primer/beta/truncate.css.json +6 -0
  74. data/app/components/primer/component.rb +34 -0
  75. data/app/components/primer/navigation/tab_component.rb +3 -157
  76. data/app/components/primer/primer.d.ts +2 -0
  77. data/app/components/primer/primer.js +2 -0
  78. data/app/components/primer/primer.pcss +3 -0
  79. data/app/components/primer/primer.ts +2 -0
  80. data/app/components/primer/truncate.css.json +7 -0
  81. data/app/lib/primer/css/layout.css.json +263 -0
  82. data/app/lib/primer/css/utilities.css.json +1636 -0
  83. data/lib/primer/deprecations.yml +4 -0
  84. data/lib/primer/view_components/linters/base_linter.rb +1 -1
  85. data/lib/primer/view_components/linters/disallow_component_css_counter.rb +30 -0
  86. data/lib/primer/view_components/version.rb +2 -2
  87. data/lib/primer/yard/component_manifest.rb +3 -1
  88. data/lib/tasks/docs.rake +1 -1
  89. data/previews/primer/alpha/action_list_preview.rb +6 -14
  90. data/previews/primer/alpha/nav_list_preview/trailing_action.html.erb +19 -0
  91. data/previews/primer/alpha/nav_list_preview.rb +19 -30
  92. data/previews/primer/alpha/overlay_preview/middle_of_page.html.erb +17 -0
  93. data/previews/primer/alpha/overlay_preview.rb +112 -0
  94. data/previews/primer/alpha/tab_nav_preview/with_extra.html.erb +8 -0
  95. data/previews/primer/alpha/tab_nav_preview.rb +5 -0
  96. data/previews/primer/alpha/tab_panels_preview/with_extra.html.erb +17 -0
  97. data/previews/primer/alpha/tab_panels_preview.rb +5 -0
  98. data/static/arguments.json +167 -7
  99. data/static/audited_at.json +6 -1
  100. data/static/classes.json +311 -0
  101. data/static/constants.json +122 -8
  102. data/static/previews.json +31 -0
  103. data/static/statuses.json +7 -2
  104. metadata +25 -6
  105. data/app/components/primer/alpha/nav_list/section.html.erb +0 -3
  106. data/previews/primer/alpha/action_list_preview/heading.html.erb +0 -4
  107. /data/app/components/primer/{navigation/tab_component.html.erb → alpha/navigation/tab.html.erb} +0 -0
@@ -0,0 +1,207 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Primer
4
+ module Alpha
5
+ # Overlay components codify design patterns related to floating surfaces such
6
+ # as dialogs and menus. They are private components intended to be used by
7
+ # specialized components, and mostly contain presentational logic and
8
+ # behavior.
9
+ #
10
+ # @accessibility
11
+ # - **Overlay Accessible Name**: An overlay should have an accessible name,
12
+ # so screen readers are aware of the purpose of the Overlay when it opens.
13
+ # Give an accessible name setting `:title`. The accessible name will be
14
+ # used as the main heading inside the Overlay.
15
+ # - **Overlay unique id**: A Overlay should be unique. Give a unique id
16
+ # setting `:id`. If no `:id` is given, a default randomize hex id is
17
+ # generated.
18
+ #
19
+ # The combination of both `:title` and `:id` establishes an
20
+ # `aria-labelledby` relationship between the title and the unique id
21
+ # of the Overlay.
22
+ class Overlay < Primer::Component
23
+ DEFAULT_PADDING = :normal
24
+ PADDING_MAPPINGS = {
25
+ DEFAULT_PADDING => nil,
26
+ :condensed => "Overlay-body--paddingCondensed",
27
+ :none => "Overlay-body--paddingNone"
28
+ }.freeze
29
+
30
+ PADDING_OPTIONS = PADDING_MAPPINGS.keys
31
+
32
+ DEFAULT_SIZE = :auto
33
+ SIZE_MAPPINGS = {
34
+ DEFAULT_SIZE => "Overlay--size-auto",
35
+ :small => "Overlay--size-small",
36
+ :medium => "Overlay--size-medium",
37
+ :medium_portrait => "Overlay--size-medium-portrait",
38
+ :large => "Overlay--size-large",
39
+ :xlarge => "Overlay--size-xlarge"
40
+ }.freeze
41
+ SIZE_OPTIONS = SIZE_MAPPINGS.keys
42
+
43
+ DEFAULT_ANCHOR_ALIGN = :start
44
+ ANCHOR_ALIGN_OPTIONS = [DEFAULT_ANCHOR_ALIGN, :center, :end].freeze
45
+
46
+ DEFAULT_ANCHOR_OFFSET = :normal
47
+ ANCHOR_OFFSET_OPTIONS = [DEFAULT_ANCHOR_OFFSET, :spacious].freeze
48
+
49
+ DEFAULT_ANCHOR_SIDE = :outside_bottom
50
+ ANCHOR_SIDE_MAPPINGS = {
51
+ :inside_top => "inside-top",
52
+ :inside_bottom => "inside-bottom",
53
+ :inside_left => "inside-left",
54
+ :inside_right => "inside-right",
55
+ :inside_center => "inside-center",
56
+ :outside_top => "outside-top",
57
+ DEFAULT_ANCHOR_SIDE => "outside-bottom",
58
+ :outside_left => "outside-left",
59
+ :outside_right => "outside-right"
60
+ }.freeze
61
+ ANCHOR_SIDE_OPTIONS = ANCHOR_SIDE_MAPPINGS.keys
62
+
63
+ DEFAULT_POPOVER = :auto
64
+ POPOVER_OPTIONS = [DEFAULT_POPOVER, :manual].freeze
65
+
66
+ ROLE_OPTIONS = [:dialog, :menu].freeze
67
+
68
+ # Optional button to open the Overlay.
69
+ #
70
+ # @param system_arguments [Hash] The same arguments as <%= link_to_component(Primer::ButtonComponent) %>.
71
+ renders_one :show_button, lambda { |icon: nil, **system_arguments|
72
+ system_arguments[:classes] = class_names(
73
+ system_arguments[:classes]
74
+ )
75
+ system_arguments[:id] = show_button_id
76
+ system_arguments["popovertoggletarget"] = overlay_id
77
+ system_arguments[:aria] = (system_arguments[:aria] || {}).merge({ controls: overlay_id, haspopup: "true" })
78
+ if icon.present?
79
+ Primer::Beta::IconButton.new(icon: icon, **system_arguments)
80
+ else
81
+ Primer::Beta::Button.new(**system_arguments)
82
+ end
83
+ }
84
+
85
+ # Header content.
86
+ #
87
+ # @param divider [Boolean] Show a divider between the header and body.
88
+ # @param visually_hide_title [Boolean] Visually hide the `title` while maintaining a label for assistive technologies.
89
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
90
+ renders_one :header, lambda { |divider: false, size: :medium, visually_hide_title: @visually_hide_title, **system_arguments|
91
+ Primer::Alpha::Overlay::Header.new(
92
+ id: @id,
93
+ title: @title,
94
+ subtitle: @subtitle,
95
+ size: size,
96
+ divider: divider,
97
+ visually_hide_title: visually_hide_title,
98
+ **system_arguments
99
+ )
100
+ }
101
+
102
+ # Required body content.
103
+ #
104
+ # @param padding [Symbol] The padding. <%= one_of(Primer::Alpha::Overlay::PADDING_OPTIONS) %>
105
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
106
+ renders_one :body, lambda { |padding: @padding, **system_arguments|
107
+ Primer::Alpha::Overlay::Body.new(
108
+ padding: padding,
109
+ **system_arguments
110
+ )
111
+ }
112
+
113
+ # Footer content.
114
+ #
115
+ # @param show_divider [Boolean] Show a divider between the footer and body.
116
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
117
+ renders_one :footer, "Footer"
118
+
119
+ # @example Overlay with Cancel and Submit buttons
120
+ # @description
121
+ # An ID is provided which enables wiring of the open and close buttons to the Overlay.
122
+ # @code
123
+ # <%= render(Primer::Alpha::Overlay.new(
124
+ # title: "Overlay Example",
125
+ # id: "my-Overlay",
126
+ # role: :dialog,
127
+ # )) do |d| %>
128
+ # <% d.with_show_button { "Show Overlay" } %>
129
+ # <% d.with_body do %>
130
+ # <p>Some content</p>
131
+ # <% end %>
132
+ # <% end %>
133
+ # @param id [String] The id of the Overlay.
134
+ # @param title [String] Describes the content of the Overlay.
135
+ # @param subtitle [String] Provides dditional context for the Overlay, also setting the `aria-describedby` attribute.
136
+ # @param popover [Symbol] The popover behaviour. <%= one_of(Primer::Alpha::Overlay::POPOVER_OPTIONS) %>
137
+ # @param popover [Symbol] The popover behaviour. <%= one_of(Primer::Alpha::Overlay::POPOVER_OPTIONS) %>
138
+ # @param size [Symbol] The size of the Overlay. <%= one_of(Primer::Alpha::Overlay::SIZE_OPTIONS) %>
139
+ # @param padding [Symbol] The padding given to the Overlay body. <%= one_of(Primer::Alpha::Overlay::PADDING_OPTIONS) %>
140
+ # @param anchor [String] An ID of the element to anchor onto. Defaults to the `show_button`.
141
+ # @param anchor_align [Symbol] The anchor alignment of the Overlay. <%= one_of(Primer::Alpha::Overlay::ANCHOR_ALIGN_OPTIONS) %>
142
+ # @param anchor_side [Symbol] The side to anchor the Overlay to. <%= one_of(Primer::Alpha::Overlay::ANCHOR_SIDE_OPTIONS) %>
143
+ # @param anchor_offset [Symbol] The anchor offset to give the Overlay. <%= one_of(Primer::Alpha::Overlay::ANCHOR_OFFSET_OPTIONS) %>
144
+ # @param allow_out_of_bounds [Boolean] Allow the Overlay to overflow its container.
145
+ # @param visually_hide_title [Boolean] If true will hide the heading title, while still making it available to Screen Readers.
146
+ # @param role [String] The ARIA role. <%= one_of(Primer::Alpha::Overlay::ROLE_OPTIONS) %>
147
+ # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
148
+ def initialize(
149
+ title:,
150
+ role:,
151
+ subtitle: nil,
152
+ popover: DEFAULT_POPOVER,
153
+ size: DEFAULT_SIZE,
154
+ padding: DEFAULT_PADDING,
155
+ anchor: nil,
156
+ anchor_align: DEFAULT_ANCHOR_ALIGN,
157
+ anchor_offset: DEFAULT_ANCHOR_OFFSET,
158
+ anchor_side: DEFAULT_ANCHOR_SIDE,
159
+ allow_out_of_bounds: false,
160
+ visually_hide_title: false,
161
+ id: self.class.generate_id,
162
+ **system_arguments
163
+ )
164
+ @system_arguments = deny_tag_argument(**system_arguments)
165
+
166
+ @system_arguments[:role] = fetch_or_fallback(ROLE_OPTIONS, role)
167
+
168
+ @system_arguments[:id] = id.to_s
169
+ @system_arguments[:classes] = class_names(
170
+ "Overlay",
171
+ SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)],
172
+ system_arguments[:classes]
173
+ )
174
+ @system_arguments[:tag] = "anchored-position"
175
+ @system_arguments[:anchor] = anchor || "overlay-show-#{@system_arguments[:id]}"
176
+ @system_arguments[:align] = fetch_or_fallback(ANCHOR_ALIGN_OPTIONS, anchor_align, DEFAULT_ANCHOR_ALIGN)
177
+ @system_arguments[:side] = ANCHOR_SIDE_MAPPINGS[fetch_or_fallback(ANCHOR_SIDE_OPTIONS, anchor_side, DEFAULT_ANCHOR_SIDE)]
178
+ @system_arguments["anchor-offset"] = fetch_or_fallback(ANCHOR_OFFSET_OPTIONS, anchor_offset, DEFAULT_ANCHOR_OFFSET)
179
+ @system_arguments["allow-out-of-bounds"] = true if allow_out_of_bounds
180
+ @id = id.to_s
181
+ @title = title
182
+ @subtitle = subtitle
183
+ @visually_hide_title = visually_hide_title
184
+ @padding = padding
185
+
186
+ @system_arguments[:popover] = popover
187
+ @system_arguments[:aria] ||= {}
188
+ @system_arguments[:aria][:describedby] ||= "#{@id}-description"
189
+ end
190
+
191
+ def before_render
192
+ with_header unless header?
193
+ with_body unless body?
194
+ end
195
+
196
+ private
197
+
198
+ def overlay_id
199
+ @system_arguments[:id]
200
+ end
201
+
202
+ def show_button_id
203
+ "overlay-show-#{overlay_id}"
204
+ end
205
+ end
206
+ end
207
+ end
@@ -27,5 +27,20 @@
27
27
  ".SegmentedControl--fullWidth .SegmentedControl-item",
28
28
  ".SegmentedControl--fullWidth .Button--iconOnly",
29
29
  ".SegmentedControl--fullWidth .Button-withTooltip"
30
+ ],
31
+ "classes": [
32
+ "SegmentedControl",
33
+ "SegmentedControl-item",
34
+ "SegmentedControl-item--selected",
35
+ "Button",
36
+ "Button-label",
37
+ "Button--small",
38
+ "Button--iconOnly",
39
+ "Button--medium",
40
+ "Button--large",
41
+ "Button--invisible",
42
+ "Button--invisible-noVisuals",
43
+ "SegmentedControl--fullWidth",
44
+ "Button-withTooltip"
30
45
  ]
31
46
  }
@@ -20,5 +20,15 @@
20
20
  ".tabnav-extra>.octicon",
21
21
  "a.tabnav-extra:hover",
22
22
  ".tabnav-btn"
23
+ ],
24
+ "classes": [
25
+ "tabnav",
26
+ "tabnav-tabs",
27
+ "tabnav-tab",
28
+ "selected",
29
+ "octicon",
30
+ "Counter",
31
+ "tabnav-extra",
32
+ "tabnav-btn"
23
33
  ]
24
34
  }
@@ -9,7 +9,7 @@ module Primer
9
9
  # - By default, `TabNav` renders links within a `<nav>` element. `<nav>` has an
10
10
  # implicit landmark role of `navigation` which should be reserved for main links.
11
11
  # For all other set of links, set tag to `:div`.
12
- # - See <%= link_to_component(Primer::Navigation::TabComponent) %> for additional
12
+ # - See <%= link_to_component(Primer::Alpha::Navigation::Tab) %> for additional
13
13
  # accessibility considerations.
14
14
  class TabNav < Primer::Component
15
15
  include Primer::TabbedComponentHelper
@@ -22,13 +22,13 @@ module Primer
22
22
  TAG_DEFAULT = :nav
23
23
  TAG_OPTIONS = [TAG_DEFAULT, :div].freeze
24
24
 
25
- # Tabs to be rendered. For more information, refer to <%= link_to_component(Primer::Navigation::TabComponent) %>.
25
+ # Tabs to be rendered. For more information, refer to <%= link_to_component(Primer::Alpha::Navigation::Tab) %>.
26
26
  #
27
27
  # @param selected [Boolean] Whether the tab is selected.
28
28
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
29
29
  renders_many :tabs, lambda { |selected: false, **system_arguments|
30
30
  system_arguments[:classes] = tab_nav_tab_classes(system_arguments[:classes])
31
- Primer::Navigation::TabComponent.new(
31
+ Primer::Alpha::Navigation::Tab.new(
32
32
  list: true,
33
33
  selected: selected,
34
34
  **system_arguments
@@ -124,6 +124,13 @@ module Primer
124
124
 
125
125
  aria_label_for_page_nav(label)
126
126
  end
127
+
128
+ def before_render
129
+ # Eagerly evaluate content to avoid https://github.com/primer/view_components/issues/1790
130
+ content
131
+
132
+ super
133
+ end
127
134
  end
128
135
  end
129
136
  end
@@ -14,7 +14,7 @@ module Primer
14
14
  TAG_DEFAULT = :nav
15
15
  TAG_OPTIONS = [TAG_DEFAULT, :div].freeze
16
16
 
17
- # Tabs to be rendered. For more information, refer to <%= link_to_component(Primer::Navigation::TabComponent) %>.
17
+ # Tabs to be rendered. For more information, refer to <%= link_to_component(Primer::Alpha::Navigation::Tab) %>.
18
18
  #
19
19
  # @param id [String] Unique ID of tab.
20
20
  # @param selected [Boolean] Whether the tab is selected.
@@ -23,7 +23,7 @@ module Primer
23
23
  system_arguments[:id] = id
24
24
  system_arguments[:classes] = tab_nav_tab_classes(system_arguments[:classes])
25
25
 
26
- Primer::Navigation::TabComponent.new(
26
+ Primer::Alpha::Navigation::Tab.new(
27
27
  selected: selected,
28
28
  with_panel: true,
29
29
  list: true,
@@ -130,5 +130,43 @@
130
130
  "input.FormControl-radio[type=radio]:checked",
131
131
  "input.FormControl-radio[type=radio]:checked:disabled",
132
132
  "input.FormControl-radio[type=radio]:focus-visible"
133
+ ],
134
+ "classes": [
135
+ "FormControl",
136
+ "FormControl--fullWidth",
137
+ "FormControl-label",
138
+ "FormControl-caption",
139
+ "FormControl-inlineValidation",
140
+ "FormControl-spacingWrapper",
141
+ "FormControl-horizontalGroup",
142
+ "FormControl-input",
143
+ "FormControl-select",
144
+ "FormControl-textarea",
145
+ "FormControl-small",
146
+ "FormControl-medium",
147
+ "FormControl-large",
148
+ "FormControl-inset",
149
+ "FormControl-monospace",
150
+ "FormControl-error",
151
+ "FormControl-success",
152
+ "FormControl-warning",
153
+ "FormControl-toggleSwitchInput",
154
+ "FormControl-input-wrap",
155
+ "FormControl-input-leadingVisualWrap",
156
+ "FormControl-input-leadingVisual",
157
+ "FormControl-input-trailingAction",
158
+ "FormControl-input-trailingAction--divider",
159
+ "FormControl-input-wrap--leadingVisual",
160
+ "FormControl-input-wrap--trailingAction",
161
+ "FormControl-input-wrap-trailingAction--divider",
162
+ "FormControl-select-wrap",
163
+ "FormControl-checkbox-wrap",
164
+ "FormControl-radio-wrap",
165
+ "FormControl-checkbox-labelWrap",
166
+ "FormControl-radio-labelWrap",
167
+ "FormControl-check-group-wrap",
168
+ "FormControl-radio-group-wrap",
169
+ "FormControl-checkbox",
170
+ "FormControl-radio"
133
171
  ]
134
172
  }
@@ -36,5 +36,21 @@
36
36
  ".ToggleSwitch-statusOff",
37
37
  ".ToggleSwitch--statusAtEnd",
38
38
  ".ToggleSwitch--statusAtEnd .ToggleSwitch-status"
39
+ ],
40
+ "classes": [
41
+ "ToggleSwitch",
42
+ "ToggleSwitch--checked",
43
+ "ToggleSwitch-statusOn",
44
+ "ToggleSwitch-statusOff",
45
+ "ToggleSwitch-track",
46
+ "ToggleSwitch-knob",
47
+ "ToggleSwitch-lineIcon",
48
+ "ToggleSwitch-circleIcon",
49
+ "ToggleSwitch-icons",
50
+ "ToggleSwitch-status",
51
+ "ToggleSwitch-statusIcon",
52
+ "ToggleSwitch--small",
53
+ "ToggleSwitch--disabled",
54
+ "ToggleSwitch--statusAtEnd"
39
55
  ]
40
56
  }
@@ -1 +1 @@
1
- .UnderlineNav{-webkit-overflow-scrolling:auto;box-shadow:inset 0 -1px 0 var(--color-border-muted);display:flex;justify-content:space-between;min-height:var(--base-size-48,48px);overflow-x:auto;overflow-y:hidden}.UnderlineNav .Counter{background-color:var(--color-neutral-muted);color:var(--color-fg-default);margin-left:var(--primer-control-medium-gap,8px)}.UnderlineNav .Counter--primary{background-color:var(--color-neutral-emphasis);color:var(--color-fg-on-emphasis)}.UnderlineNav-body{align-items:center;display:flex;gap:var(--primer-control-medium-gap,8px);list-style:none}.UnderlineNav-item{align-items:center;background-color:initial;border:0;border-radius:var(--primer-borderRadius-medium,6px);color:var(--color-fg-default);cursor:pointer;display:flex;font-size:var(--primer-text-body-size-medium,14px);line-height:30px;padding:0 var(--primer-control-medium-paddingInline-condensed,8px);position:relative;text-align:center;white-space:nowrap}.UnderlineNav-item:focus,.UnderlineNav-item:focus-visible,.UnderlineNav-item:hover{border-bottom-color:var(--color-neutral-muted);color:var(--color-fg-default);outline-offset:-2px;text-decoration:none;transition:border-bottom-color .12s ease-out}.UnderlineNav-item [data-content]:before{content:attr(data-content);display:block;font-weight:var(--base-text-weight-semibold,600);height:0;visibility:hidden}.UnderlineNav-item:before{content:"";height:100%;left:50%;min-height:48px;position:absolute;top:50%;transform:translateX(-50%) translateY(-50%);width:100%}@media (pointer:fine){.UnderlineNav-item:hover{background:var(--color-action-list-item-default-hover-bg);color:var(--color-fg-default);text-decoration:none;transition:background .12s ease-out}}.UnderlineNav-item.selected,.UnderlineNav-item[aria-current]:not([aria-current=false]),.UnderlineNav-item[role=tab][aria-selected=true]{border-bottom-color:var(--color-primer-border-active);color:var(--color-fg-default);font-weight:var(--base-text-weight-semibold,600)}.UnderlineNav-item.selected:after,.UnderlineNav-item[aria-current]:not([aria-current=false]):after,.UnderlineNav-item[role=tab][aria-selected=true]:after{background:var(--color-primer-border-active);border-radius:var(--primer-borderRadius-medium,6px);bottom:calc(50% - 25px);content:"";height:2px;position:absolute;right:50%;transform:translate(50%,-50%);width:100%}.UnderlineNav--right{justify-content:flex-end}.UnderlineNav--right .UnderlineNav-actions{flex:1 1 auto}.UnderlineNav-actions{align-self:center}.UnderlineNav--full{display:block}.UnderlineNav--full .UnderlineNav-body{min-height:var(--base-size-48,48px)}.UnderlineNav-octicon{fill:var(--color-fg-muted);color:var(--color-fg-muted);display:inline!important;margin-right:var(--primer-control-medium-gap,8px)}.UnderlineNav-container{display:flex;justify-content:space-between}
1
+ .UnderlineNav{-webkit-overflow-scrolling:auto;box-shadow:inset 0 -1px 0 var(--color-border-muted);display:flex;justify-content:space-between;min-height:var(--base-size-48,48px);overflow-x:auto;overflow-y:hidden}.UnderlineNav .Counter{background-color:var(--color-neutral-muted);color:var(--color-fg-default);margin-left:var(--primer-control-medium-gap,8px)}.UnderlineNav .Counter--primary{background-color:var(--color-neutral-emphasis);color:var(--color-fg-on-emphasis)}.UnderlineNav-body{align-items:center;display:flex;gap:var(--primer-control-medium-gap,8px);list-style:none}.UnderlineNav-item{align-items:center;background-color:initial;border:0;border-radius:var(--primer-borderRadius-medium,6px);color:var(--color-fg-default);cursor:pointer;display:flex;font-size:var(--primer-text-body-size-medium,14px);line-height:30px;padding:0 var(--primer-control-medium-paddingInline-condensed,8px);position:relative;text-align:center;white-space:nowrap}.UnderlineNav-item:focus,.UnderlineNav-item:focus-visible,.UnderlineNav-item:hover{border-bottom-color:var(--color-neutral-muted);color:var(--color-fg-default);outline-offset:-2px;text-decoration:none;transition:border-bottom-color .12s ease-out}.UnderlineNav-item [data-content]:before{content:attr(data-content);display:block;font-weight:var(--base-text-weight-semibold,600);height:0;visibility:hidden}.UnderlineNav-item:before{content:"";height:100%;left:50%;min-height:48px;position:absolute;top:50%;transform:translateX(-50%) translateY(-50%);width:100%}@media (pointer:fine){.UnderlineNav-item:hover{background:var(--color-action-list-item-default-hover-bg);color:var(--color-fg-default);text-decoration:none;transition:background .12s ease-out}}.UnderlineNav-item.selected,.UnderlineNav-item[aria-current]:not([aria-current=false]),.UnderlineNav-item[role=tab][aria-selected=true]{border-bottom-color:var(--color-primer-border-active);color:var(--color-fg-default);font-weight:var(--base-text-weight-semibold,600)}.UnderlineNav-item.selected:after,.UnderlineNav-item[aria-current]:not([aria-current=false]):after,.UnderlineNav-item[role=tab][aria-selected=true]:after{background:var(--color-primer-border-active);border-radius:var(--primer-borderRadius-medium,6px);bottom:calc(50% - 25px);content:"";height:2px;position:absolute;right:50%;transform:translate(50%,-50%);width:100%;z-index:1}.UnderlineNav--right{justify-content:flex-end}.UnderlineNav--right .UnderlineNav-actions{flex:1 1 auto}.UnderlineNav-actions{align-self:center}.UnderlineNav--full{display:block}.UnderlineNav--full .UnderlineNav-body{min-height:var(--base-size-48,48px)}.UnderlineNav-octicon{fill:var(--color-fg-muted);color:var(--color-fg-muted);display:inline!important;margin-right:var(--primer-control-medium-gap,8px)}.UnderlineNav-container{display:flex;justify-content:space-between}
@@ -24,5 +24,18 @@
24
24
  ".UnderlineNav--full .UnderlineNav-body",
25
25
  ".UnderlineNav-octicon",
26
26
  ".UnderlineNav-container"
27
+ ],
28
+ "classes": [
29
+ "UnderlineNav",
30
+ "Counter",
31
+ "Counter--primary",
32
+ "UnderlineNav-body",
33
+ "UnderlineNav-item",
34
+ "selected",
35
+ "UnderlineNav--right",
36
+ "UnderlineNav-actions",
37
+ "UnderlineNav--full",
38
+ "UnderlineNav-octicon",
39
+ "UnderlineNav-container"
27
40
  ]
28
41
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["underline_nav.pcss","<no source>"],"names":[],"mappings":"AAEA,cAME,+BAAgC,CADhC,mDAAoD,CAJpD,YAAa,CAMb,6BAA8B,CAL9B,mCAAqC,CACrC,eAAgB,CAChB,iBAeF,CAVE,uBAGE,2CAA4C,CAD5C,6BAA8B,CAD9B,gDAGF,CAEA,gCAEE,8CAA+C,CAD/C,iCAEF,CAGF,mBAEE,kBAAmB,CADnB,YAAa,CAEb,wCAA0C,CAC1C,eACF,CAEA,mBAaE,kBAAmB,CAHnB,wBAA6B,CAC7B,QAAS,CACT,mDAAqD,CANrD,6BAA8B,CAG9B,cAAe,CAPf,YAAa,CAEb,kDAAoD,CACpD,gBAAiB,CAFjB,kEAAoE,CAFpE,iBAAkB,CAMlB,iBAAkB,CAClB,kBA6DF,CAtDE,mFAKE,8CAA+C,CAF/C,6BAA8B,CAG9B,mBAAoB,CAFpB,oBAAqB,CAGrB,4CACF,CAGA,yCAKE,0BAA2B,CAJ3B,aAAc,CAEd,gDAAkD,CADlD,QAAS,CAET,iBAEF,CAIE,0BClEJ,WAAA,YAAA,SAAA,gBAAA,kBAAA,QAAA,4CAAA,UDkE8B,CAI5B,sBACE,yBAGE,yDAA0D,CAF1D,6BAA8B,CAC9B,oBAAqB,CAErB,mCACF,CACF,CAEA,wIAKE,qDAAsD,CADtD,6BAA8B,CAD9B,gDAgBF,CAXE,0JAOE,4CAA6C,CAC7C,mDAAqD,CALrD,uBAAwB,CAGxB,UAAW,CADX,UAAW,CAJX,iBAAkB,CAClB,SAAU,CAOV,6BAA+B,CAL/B,UAMF,CAIJ,qBACE,wBAKF,CAHE,2CACE,aACF,CAGF,sBACE,iBACF,CAEA,oBACE,aAMF,CAHE,uCACE,mCACF,CAGF,sBAIE,0BAA2B,CAD3B,2BAA4B,CAF5B,wBAA0B,CAC1B,iDAGF,CAEA,wBACE,YAAa,CACb,6BACF","file":"underline_nav.css","sourcesContent":["/* UnderlineNav */\n\n.UnderlineNav {\n display: flex;\n min-height: var(--base-size-48, 48px);\n overflow-x: auto;\n overflow-y: hidden;\n box-shadow: inset 0 -1px 0 var(--color-border-muted);\n -webkit-overflow-scrolling: auto;\n justify-content: space-between;\n\n & .Counter {\n margin-left: var(--primer-control-medium-gap, 8px);\n color: var(--color-fg-default);\n background-color: var(--color-neutral-muted);\n }\n\n & .Counter--primary {\n color: var(--color-fg-on-emphasis);\n background-color: var(--color-neutral-emphasis);\n }\n}\n\n.UnderlineNav-body {\n display: flex;\n align-items: center;\n gap: var(--primer-control-medium-gap, 8px);\n list-style: none;\n}\n\n.UnderlineNav-item {\n position: relative;\n display: flex;\n padding: 0 var(--primer-control-medium-paddingInline-condensed, 8px);\n font-size: var(--primer-text-body-size-medium, 14px);\n line-height: 30px;\n color: var(--color-fg-default);\n text-align: center;\n white-space: nowrap;\n cursor: pointer;\n background-color: transparent;\n border: 0;\n border-radius: var(--primer-borderRadius-medium, 6px);\n align-items: center;\n\n &:hover,\n &:focus,\n &:focus-visible {\n color: var(--color-fg-default);\n text-decoration: none;\n border-bottom-color: var(--color-neutral-muted);\n outline-offset: -2px;\n transition: border-bottom-color 0.12s ease-out;\n }\n\n /* renders a visibly hidden \"copy\" of the label in bold, reserving box space for when label becomes bold on selected */\n & [data-content]::before {\n display: block;\n height: 0;\n font-weight: var(--base-text-weight-semibold, 600);\n visibility: hidden;\n content: attr(data-content);\n }\n\n /* increase touch target area */\n &::before {\n @mixin minTouchTarget 48px;\n }\n\n /* hover state was \"sticking\" on mobile after click */\n @media (pointer: fine) {\n &:hover {\n color: var(--color-fg-default);\n text-decoration: none;\n background: var(--color-action-list-item-default-hover-bg);\n transition: background 0.12s ease-out;\n }\n }\n\n &.selected,\n &[role='tab'][aria-selected='true'],\n &[aria-current]:not([aria-current='false']) {\n font-weight: var(--base-text-weight-semibold, 600);\n color: var(--color-fg-default);\n border-bottom-color: var(--color-primer-border-active);\n\n /* current/selected underline */\n &::after {\n position: absolute;\n right: 50%;\n bottom: calc(50% - 25px); /* 48px total height / 2 (24px) + 1px */\n width: 100%;\n height: 2px;\n content: '';\n background: var(--color-primer-border-active);\n border-radius: var(--primer-borderRadius-medium, 6px);\n transform: translate(50%, -50%);\n }\n }\n}\n\n.UnderlineNav--right {\n justify-content: flex-end;\n\n & .UnderlineNav-actions {\n flex: 1 1 auto;\n }\n}\n\n.UnderlineNav-actions {\n align-self: center;\n}\n\n.UnderlineNav--full {\n display: block;\n\n /* required for underline to align with additional wrapper element */\n & .UnderlineNav-body {\n min-height: var(--base-size-48, 48px);\n }\n}\n\n.UnderlineNav-octicon {\n display: inline !important;\n margin-right: var(--primer-control-medium-gap, 8px);\n color: var(--color-fg-muted);\n fill: var(--color-fg-muted);\n}\n\n.UnderlineNav-container {\n display: flex;\n justify-content: space-between;\n}\n",null]}
1
+ {"version":3,"sources":["underline_nav.pcss","<no source>"],"names":[],"mappings":"AAEA,cAME,+BAAgC,CADhC,mDAAoD,CAJpD,YAAa,CAMb,6BAA8B,CAL9B,mCAAqC,CACrC,eAAgB,CAChB,iBAeF,CAVE,uBAGE,2CAA4C,CAD5C,6BAA8B,CAD9B,gDAGF,CAEA,gCAEE,8CAA+C,CAD/C,iCAEF,CAGF,mBAEE,kBAAmB,CADnB,YAAa,CAEb,wCAA0C,CAC1C,eACF,CAEA,mBAaE,kBAAmB,CAHnB,wBAA6B,CAC7B,QAAS,CACT,mDAAqD,CANrD,6BAA8B,CAG9B,cAAe,CAPf,YAAa,CAEb,kDAAoD,CACpD,gBAAiB,CAFjB,kEAAoE,CAFpE,iBAAkB,CAMlB,iBAAkB,CAClB,kBA8DF,CAvDE,mFAKE,8CAA+C,CAF/C,6BAA8B,CAG9B,mBAAoB,CAFpB,oBAAqB,CAGrB,4CACF,CAGA,yCAKE,0BAA2B,CAJ3B,aAAc,CAEd,gDAAkD,CADlD,QAAS,CAET,iBAEF,CAIE,0BClEJ,WAAA,YAAA,SAAA,gBAAA,kBAAA,QAAA,4CAAA,UDkE8B,CAI5B,sBACE,yBAGE,yDAA0D,CAF1D,6BAA8B,CAC9B,oBAAqB,CAErB,mCACF,CACF,CAEA,wIAKE,qDAAsD,CADtD,6BAA8B,CAD9B,gDAiBF,CAZE,0JAQE,4CAA6C,CAC7C,mDAAqD,CALrD,uBAAwB,CAGxB,UAAW,CADX,UAAW,CALX,iBAAkB,CAElB,SAAU,CAOV,6BAA+B,CAL/B,UAAW,CAHX,SASF,CAIJ,qBACE,wBAKF,CAHE,2CACE,aACF,CAGF,sBACE,iBACF,CAEA,oBACE,aAMF,CAHE,uCACE,mCACF,CAGF,sBAIE,0BAA2B,CAD3B,2BAA4B,CAF5B,wBAA0B,CAC1B,iDAGF,CAEA,wBACE,YAAa,CACb,6BACF","file":"underline_nav.css","sourcesContent":["/* UnderlineNav */\n\n.UnderlineNav {\n display: flex;\n min-height: var(--base-size-48, 48px);\n overflow-x: auto;\n overflow-y: hidden;\n box-shadow: inset 0 -1px 0 var(--color-border-muted);\n -webkit-overflow-scrolling: auto;\n justify-content: space-between;\n\n & .Counter {\n margin-left: var(--primer-control-medium-gap, 8px);\n color: var(--color-fg-default);\n background-color: var(--color-neutral-muted);\n }\n\n & .Counter--primary {\n color: var(--color-fg-on-emphasis);\n background-color: var(--color-neutral-emphasis);\n }\n}\n\n.UnderlineNav-body {\n display: flex;\n align-items: center;\n gap: var(--primer-control-medium-gap, 8px);\n list-style: none;\n}\n\n.UnderlineNav-item {\n position: relative;\n display: flex;\n padding: 0 var(--primer-control-medium-paddingInline-condensed, 8px);\n font-size: var(--primer-text-body-size-medium, 14px);\n line-height: 30px;\n color: var(--color-fg-default);\n text-align: center;\n white-space: nowrap;\n cursor: pointer;\n background-color: transparent;\n border: 0;\n border-radius: var(--primer-borderRadius-medium, 6px);\n align-items: center;\n\n &:hover,\n &:focus,\n &:focus-visible {\n color: var(--color-fg-default);\n text-decoration: none;\n border-bottom-color: var(--color-neutral-muted);\n outline-offset: -2px;\n transition: border-bottom-color 0.12s ease-out;\n }\n\n /* renders a visibly hidden \"copy\" of the label in bold, reserving box space for when label becomes bold on selected */\n & [data-content]::before {\n display: block;\n height: 0;\n font-weight: var(--base-text-weight-semibold, 600);\n visibility: hidden;\n content: attr(data-content);\n }\n\n /* increase touch target area */\n &::before {\n @mixin minTouchTarget 48px;\n }\n\n /* hover state was \"sticking\" on mobile after click */\n @media (pointer: fine) {\n &:hover {\n color: var(--color-fg-default);\n text-decoration: none;\n background: var(--color-action-list-item-default-hover-bg);\n transition: background 0.12s ease-out;\n }\n }\n\n &.selected,\n &[role='tab'][aria-selected='true'],\n &[aria-current]:not([aria-current='false']) {\n font-weight: var(--base-text-weight-semibold, 600);\n color: var(--color-fg-default);\n border-bottom-color: var(--color-primer-border-active);\n\n /* current/selected underline */\n &::after {\n position: absolute;\n z-index: 1; /* raise above full-width flash banner */\n right: 50%;\n bottom: calc(50% - 25px); /* 48px total height / 2 (24px) + 1px */\n width: 100%;\n height: 2px;\n content: '';\n background: var(--color-primer-border-active);\n border-radius: var(--primer-borderRadius-medium, 6px);\n transform: translate(50%, -50%);\n }\n }\n}\n\n.UnderlineNav--right {\n justify-content: flex-end;\n\n & .UnderlineNav-actions {\n flex: 1 1 auto;\n }\n}\n\n.UnderlineNav-actions {\n align-self: center;\n}\n\n.UnderlineNav--full {\n display: block;\n\n /* required for underline to align with additional wrapper element */\n & .UnderlineNav-body {\n min-height: var(--base-size-48, 48px);\n }\n}\n\n.UnderlineNav-octicon {\n display: inline !important;\n margin-right: var(--primer-control-medium-gap, 8px);\n color: var(--color-fg-muted);\n fill: var(--color-fg-muted);\n}\n\n.UnderlineNav-container {\n display: flex;\n justify-content: space-between;\n}\n",null]}
@@ -87,6 +87,7 @@
87
87
  /* current/selected underline */
88
88
  &::after {
89
89
  position: absolute;
90
+ z-index: 1; /* raise above full-width flash banner */
90
91
  right: 50%;
91
92
  bottom: calc(50% - 25px); /* 48px total height / 2 (24px) + 1px */
92
93
  width: 100%;
@@ -12,7 +12,7 @@ module Primer
12
12
  # - By default, `UnderlineNav` renders links within a `<nav>` element. `<nav>` has an
13
13
  # implicit landmark role of `navigation` which should be reserved for main links.
14
14
  # For all other set of links, set tag to `:div`.
15
- # - See <%= link_to_component(Primer::Navigation::TabComponent) %> for additional
15
+ # - See <%= link_to_component(Primer::Alpha::Navigation::Tab) %> for additional
16
16
  # accessibility considerations.
17
17
  class UnderlineNav < Primer::Component
18
18
  include Primer::TabbedComponentHelper
@@ -29,7 +29,7 @@ module Primer
29
29
  # @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
30
30
  renders_many :tabs, lambda { |selected: false, **system_arguments|
31
31
  system_arguments[:classes] = underline_nav_tab_classes(system_arguments[:classes])
32
- Primer::Navigation::TabComponent.new(
32
+ Primer::Alpha::Navigation::Tab.new(
33
33
  list: true,
34
34
  selected: selected,
35
35
  icon_classes: "UnderlineNav-octicon",
@@ -6,7 +6,7 @@ module Primer
6
6
  class UnderlinePanels < Primer::Component
7
7
  include Primer::TabbedComponentHelper
8
8
  include Primer::UnderlineNavHelper
9
- # Use to render a button and an associated panel slot. See the example below or refer to <%= link_to_component(Primer::Navigation::TabComponent) %>.
9
+ # Use to render a button and an associated panel slot. See the example below or refer to <%= link_to_component(Primer::Alpha::Navigation::Tab) %>.
10
10
  #
11
11
  # @param id [String] Unique ID of tab.
12
12
  # @param selected [Boolean] Whether the tab is selected.
@@ -15,7 +15,7 @@ module Primer
15
15
  system_arguments[:id] = id
16
16
  system_arguments[:classes] = underline_nav_tab_classes(system_arguments[:classes])
17
17
 
18
- Primer::Navigation::TabComponent.new(
18
+ Primer::Alpha::Navigation::Tab.new(
19
19
  selected: selected,
20
20
  with_panel: true,
21
21
  list: true,
@@ -0,0 +1,27 @@
1
+ import type { AnchorAlignment, AnchorSide, PositionSettings } from '@primer/behaviors';
2
+ export default class AnchoredPositionElement extends HTMLElement implements PositionSettings {
3
+ #private;
4
+ get align(): AnchorAlignment;
5
+ set align(value: AnchorAlignment);
6
+ get side(): AnchorSide;
7
+ set side(value: AnchorSide);
8
+ get anchorOffset(): number;
9
+ set anchorOffset(value: number | 'normal' | 'spacious');
10
+ get anchor(): string;
11
+ set anchor(value: string);
12
+ get anchorElement(): HTMLElement | null;
13
+ set anchorElement(value: HTMLElement | null);
14
+ get alignmentOffset(): number;
15
+ set alignmentOffset(value: number);
16
+ get allowOutOfBounds(): boolean;
17
+ set allowOutOfBounds(value: boolean);
18
+ connectedCallback(): void;
19
+ static observedAttributes: string[];
20
+ attributeChangedCallback(): void;
21
+ update(): void;
22
+ }
23
+ declare global {
24
+ interface Window {
25
+ AnchoredPositionElement: typeof AnchoredPositionElement;
26
+ }
27
+ }
@@ -0,0 +1,149 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _AnchoredPositionElement_anchorElement, _AnchoredPositionElement_animationFrame;
13
+ import { getAnchoredPosition } from '@primer/behaviors';
14
+ const updateWhenVisible = (() => {
15
+ const anchors = new Set();
16
+ let intersectionObserver = null;
17
+ let resizeObserver = null;
18
+ function updateVisibleAnchors() {
19
+ for (const anchor of anchors) {
20
+ anchor.update();
21
+ }
22
+ }
23
+ return (el) => {
24
+ // eslint-disable-next-line github/prefer-observers
25
+ window.addEventListener('resize', updateVisibleAnchors);
26
+ intersectionObserver || (intersectionObserver = new IntersectionObserver(entries => {
27
+ for (const entry of entries) {
28
+ const target = entry.target;
29
+ if (entry.isIntersecting) {
30
+ target.update();
31
+ anchors.add(target);
32
+ }
33
+ else {
34
+ anchors.delete(target);
35
+ }
36
+ }
37
+ }));
38
+ resizeObserver || (resizeObserver = new ResizeObserver(() => {
39
+ for (const anchor of anchors) {
40
+ anchor.update();
41
+ }
42
+ }));
43
+ resizeObserver.observe(el.ownerDocument.documentElement);
44
+ intersectionObserver.observe(el);
45
+ };
46
+ })();
47
+ export default class AnchoredPositionElement extends HTMLElement {
48
+ constructor() {
49
+ super(...arguments);
50
+ _AnchoredPositionElement_anchorElement.set(this, null);
51
+ _AnchoredPositionElement_animationFrame.set(this, void 0);
52
+ }
53
+ get align() {
54
+ const value = this.getAttribute('align');
55
+ if (value === 'center' || value === 'end')
56
+ return value;
57
+ return 'start';
58
+ }
59
+ set align(value) {
60
+ this.setAttribute('align', `${value}`);
61
+ }
62
+ get side() {
63
+ const value = this.getAttribute('side');
64
+ if (value === 'inside-top' ||
65
+ value === 'inside-bottom' ||
66
+ value === 'inside-left' ||
67
+ value === 'inside-right' ||
68
+ value === 'inside-center' ||
69
+ value === 'outside-top' ||
70
+ value === 'outside-left' ||
71
+ value === 'outside-right') {
72
+ return value;
73
+ }
74
+ return 'outside-bottom';
75
+ }
76
+ set side(value) {
77
+ this.setAttribute('side', `${value}`);
78
+ }
79
+ get anchorOffset() {
80
+ const alias = this.getAttribute('anchor-offset');
81
+ if (alias === 'spacious' || alias === '8')
82
+ return 8;
83
+ return 4;
84
+ }
85
+ set anchorOffset(value) {
86
+ this.setAttribute('anchor-offset', `${value}`);
87
+ }
88
+ get anchor() {
89
+ return this.getAttribute('anchor') || '';
90
+ }
91
+ set anchor(value) {
92
+ this.setAttribute('anchor', `${value}`);
93
+ }
94
+ get anchorElement() {
95
+ if (__classPrivateFieldGet(this, _AnchoredPositionElement_anchorElement, "f"))
96
+ return __classPrivateFieldGet(this, _AnchoredPositionElement_anchorElement, "f");
97
+ const idRef = this.anchor;
98
+ if (!idRef)
99
+ return null;
100
+ return this.ownerDocument.getElementById(idRef);
101
+ }
102
+ set anchorElement(value) {
103
+ __classPrivateFieldSet(this, _AnchoredPositionElement_anchorElement, value, "f");
104
+ if (!__classPrivateFieldGet(this, _AnchoredPositionElement_anchorElement, "f")) {
105
+ this.removeAttribute('anchor');
106
+ }
107
+ }
108
+ get alignmentOffset() {
109
+ return Number(this.getAttribute('alignment-offset'));
110
+ }
111
+ set alignmentOffset(value) {
112
+ this.setAttribute('alignment-offset', `${value}`);
113
+ }
114
+ get allowOutOfBounds() {
115
+ return this.hasAttribute('allow-out-of-bounds');
116
+ }
117
+ set allowOutOfBounds(value) {
118
+ this.toggleAttribute('allow-out-of-bounds', value);
119
+ }
120
+ connectedCallback() {
121
+ this.update();
122
+ this.addEventListener('beforetoggle', () => this.update());
123
+ updateWhenVisible(this);
124
+ }
125
+ attributeChangedCallback() {
126
+ this.update();
127
+ }
128
+ update() {
129
+ if (!this.isConnected)
130
+ return;
131
+ cancelAnimationFrame(__classPrivateFieldGet(this, _AnchoredPositionElement_animationFrame, "f"));
132
+ __classPrivateFieldSet(this, _AnchoredPositionElement_animationFrame, requestAnimationFrame(() => {
133
+ const anchor = this.anchorElement;
134
+ if (!anchor)
135
+ return;
136
+ const { left, top, anchorSide, anchorAlign } = getAnchoredPosition(this, anchor, this);
137
+ this.style.top = `${top}px`;
138
+ this.style.left = `${left}px`;
139
+ this.classList.remove('Overlay--anchorAlign-start', 'Overlay--anchorAlign-center', 'Overlay--anchorAlign-end', 'Overlay--anchorSide-insideTop', 'Overlay--anchorSide-insideBottom', 'Overlay--anchorSide-insideLeft', 'Overlay--anchorSide-insideRight', 'Overlay--anchorSide-insideCenter', 'Overlay--anchorSide-outsideTop', 'Overlay--anchorSide-outsideLeft', 'Overlay--anchorSide-outsideRight');
140
+ this.classList.add(`Overlay--anchorAlign-${anchorAlign}`, `Overlay--anchorSide-${anchorSide}`);
141
+ }), "f");
142
+ }
143
+ }
144
+ _AnchoredPositionElement_anchorElement = new WeakMap(), _AnchoredPositionElement_animationFrame = new WeakMap();
145
+ AnchoredPositionElement.observedAttributes = ['align', 'side', 'anchor', 'alignment-offset', 'allow-out-of-bounds'];
146
+ if (!customElements.get('anchored-position')) {
147
+ window.AnchoredPositionElement = AnchoredPositionElement;
148
+ customElements.define('anchored-position', AnchoredPositionElement);
149
+ }