forked from primer/view_components
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsegmented_control_preview.rb
More file actions
163 lines (147 loc) · 6.39 KB
/
Copy pathsegmented_control_preview.rb
File metadata and controls
163 lines (147 loc) · 6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# frozen_string_literal: true
# Setup Playground to use all available component props
# Setup Features to use individual component props and combinations
module Primer
module Alpha
# @label SegmentedControl
class SegmentedControlPreview < ViewComponent::Preview
# @label Playground
# @param full_width [Boolean] toggle
# @param hide_labels [Boolean] toggle
# @param icon [Symbol] octicon
# @param size select [small, medium]
def playground(full_width: false, hide_labels: false, size: :medium, icon: :none)
if icon == :none
icon = hide_labels ? :zap : nil
end
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", full_width: full_width, hide_labels: hide_labels, size: size)) do |component|
component.with_item(label: "Preview", icon: icon, selected: true)
component.with_item(label: "Raw", icon: icon)
component.with_item(label: "Blame", icon: icon)
end
end
# @label Default
# @snapshot
def default
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view")) do |component|
component.with_item(label: "Preview", selected: true)
component.with_item(label: "Raw")
component.with_item(label: "Blame")
end
end
# @!group Full width
# @label Size small
# @param hide_labels [Boolean] toggle
# @snapshot
def full_width_small(hide_labels: false)
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", hide_labels: hide_labels, full_width: true, size: :small)) do |component|
component.with_item(label: "Preview", selected: true)
component.with_item(label: "Raw")
component.with_item(label: "Blame")
end
end
# @label Size medium
# @param hide_labels [Boolean] toggle
# @snapshot
def full_width_medium(hide_labels: false)
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", hide_labels: hide_labels, full_width: true, size: :medium)) do |component|
component.with_item(label: "Preview", selected: true)
component.with_item(label: "Raw")
component.with_item(label: "Blame")
end
end
# @!endgroup
# @!group Icons and text
# @snapshot
def icons_and_text_small
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", size: :small)) do |component|
component.with_item(label: "Preview", icon: :eye, selected: true)
component.with_item(label: "Raw", icon: :"file-code")
component.with_item(label: "Blame", icon: :people)
end
end
# @label Size medium
def icons_and_text_medium
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", size: :medium)) do |component|
component.with_item(label: "Preview", icon: :eye, selected: true)
component.with_item(label: "Raw", icon: :"file-code")
component.with_item(label: "Blame", icon: :people)
end
end
# @!endgroup
# @!group Trailing Label
# @label Size small
def trailing_label_width_small
render(Primer::Alpha::SegmentedControl.new("aria-label": "Billing duration", size: :small)) do |component|
component.with_item(label: "Monthly")
component.with_item(label: "Yearly", selected: true) do |button|
button.with_trailing_visual_label(scheme: :accent) { "-8%" }
end
end
end
# @label Size medium
def trailing_label_width_medium
render(Primer::Alpha::SegmentedControl.new("aria-label": "Billing duration", size: :medium)) do |component|
component.with_item(label: "Monthly")
component.with_item(label: "Yearly", selected: true) do |button|
button.with_trailing_visual_label(scheme: :accent) { "-8%" }
end
end
end
# @!endgroup
# @!group Icons only
# @label Size small
# @snapshot
def icon_only_small
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", hide_labels: true, size: :small)) do |component|
component.with_item(label: "Preview", icon: :eye, selected: true)
component.with_item(label: "Raw", icon: :"file-code")
component.with_item(label: "Blame", icon: :people)
end
end
# @label Size medium
# @snapshot
def icon_only_medium
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", hide_labels: true, size: :medium)) do |component|
component.with_item(label: "Preview", icon: :eye, selected: true)
component.with_item(label: "Raw", icon: :"file-code")
component.with_item(label: "Blame", icon: :people)
end
end
# @label Full width, size small
def icon_only_full_width_small
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", hide_labels: true, full_width: true, size: :small)) do |component|
component.with_item(label: "Preview", icon: :eye, selected: true)
component.with_item(label: "Raw", icon: :"file-code")
component.with_item(label: "Blame", icon: :people)
end
end
# @label Full width, size medium
def icon_only_full_width_medium
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", hide_labels: true, full_width: true, size: :medium)) do |component|
component.with_item(label: "Preview", icon: :eye, selected: true)
component.with_item(label: "Raw", icon: :"file-code")
component.with_item(label: "Blame", icon: :people)
end
end
# @!endgroup
# NOTE: this preview uses a group to force it's display below the other groups
# @!group With link as tag
# @snapshot
def with_link_as_tag
render(Primer::Alpha::SegmentedControl.new("aria-label": "File view")) do |component|
component.with_item(tag: :a, href: "#", label: "Preview", icon: :eye, selected: true)
component.with_item(tag: :a, href: "#", label: "Raw", icon: :"file-code")
component.with_item(tag: :a, href: "#", label: "Blame", icon: :people)
end
end
# @!endgroup
# @!group With aria labeled headings
# @snapshot
def with_subhead_actions; end
# @snapshot
def with_label_and_caption; end
# @!endgroup
end
end
end