phlex_ui 0.1.6 → 0.1.7

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.
@@ -1,49 +1,49 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
4
- class Command::DialogContent < Base
5
- SIZES = {
6
- xs: "max-w-sm",
7
- sm: "max-w-md",
8
- md: "max-w-lg",
9
- lg: "max-w-2xl",
10
- xl: "max-w-4xl",
11
- full: "max-w-full",
12
- }
13
-
14
- def initialize(size: :md, **attrs)
15
- @size = size
16
- super(**attrs)
17
- end
4
+ class Command::DialogContent < Base
5
+ SIZES = {
6
+ xs: "max-w-sm",
7
+ sm: "max-w-md",
8
+ md: "max-w-lg",
9
+ lg: "max-w-2xl",
10
+ xl: "max-w-4xl",
11
+ full: "max-w-full"
12
+ }
13
+
14
+ def initialize(size: :md, **attrs)
15
+ @size = size
16
+ super(**attrs)
17
+ end
18
18
 
19
- def template(&block)
20
- template_tag(data: { dialog_target: "content" }) do
21
- div(data: { controller: 'dismissable' }) do
22
- backdrop
23
- div(**attrs, &block)
24
- end
25
- end
19
+ def template(&block)
20
+ template_tag(data: {dialog_target: "content"}) do
21
+ div(data: {controller: "dismissable"}) do
22
+ backdrop
23
+ div(**attrs, &block)
26
24
  end
25
+ end
26
+ end
27
27
 
28
- private
28
+ private
29
29
 
30
- def default_attrs
31
- {
32
- data_state: "open",
33
- class: tokens(
34
- "fixed pointer-events-auto left-[50%] top-[50%] z-50 grid w-full translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg md:w-full",
35
- SIZES[@size]
36
- ),
37
- }
38
- end
30
+ def default_attrs
31
+ {
32
+ data_state: "open",
33
+ class: tokens(
34
+ "fixed pointer-events-auto left-[50%] top-[50%] z-50 grid w-full translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg md:w-full",
35
+ SIZES[@size]
36
+ )
37
+ }
38
+ end
39
39
 
40
- def backdrop
41
- div(
42
- data_state: "open",
43
- data_action: "click->dismissable#dismiss esc->dismissable#dismiss",
44
- class:
45
- "fixed pointer-events-auto inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
46
- )
47
- end
40
+ def backdrop
41
+ div(
42
+ data_state: "open",
43
+ data_action: "click->dismissable#dismiss esc->dismissable#dismiss",
44
+ class:
45
+ "fixed pointer-events-auto inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"
46
+ )
48
47
  end
49
- end
48
+ end
49
+ end
@@ -1,29 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
4
- class Command::DialogTrigger < Base
5
- DEFAULT_KEYBINDINGS = [
6
- "keydown.ctrl+k@window",
7
- "keydown.meta+k@window"
8
- ].freeze
4
+ class Command::DialogTrigger < Base
5
+ DEFAULT_KEYBINDINGS = [
6
+ "keydown.ctrl+k@window",
7
+ "keydown.meta+k@window"
8
+ ].freeze
9
9
 
10
- def initialize(keybindings: DEFAULT_KEYBINDINGS, **attrs)
11
- @keybindings = keybindings.map { |kb| "#{kb}->dialog#open" }
12
- super(**attrs)
13
- end
10
+ def initialize(keybindings: DEFAULT_KEYBINDINGS, **attrs)
11
+ @keybindings = keybindings.map { |kb| "#{kb}->dialog#open" }
12
+ super(**attrs)
13
+ end
14
14
 
15
- def template(&block)
16
- div(**attrs, &block)
17
- end
15
+ def template(&block)
16
+ div(**attrs, &block)
17
+ end
18
18
 
19
- private
19
+ private
20
20
 
21
- def default_attrs
22
- {
23
- data: {
24
- action: tokens("click->dialog#open", @keybindings.join(' '))
25
- },
26
- }
27
- end
21
+ def default_attrs
22
+ {
23
+ data: {
24
+ action: tokens("click->dialog#open", @keybindings.join(" "))
25
+ }
26
+ }
28
27
  end
29
- end
28
+ end
29
+ end
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
4
- class Command::Empty < Base
5
- def template(&block)
6
- div(**attrs, &block)
7
- end
4
+ class Command::Empty < Base
5
+ def template(&block)
6
+ div(**attrs, &block)
7
+ end
8
8
 
9
- private
9
+ private
10
10
 
11
- def default_attrs
12
- {
13
- class: "py-6 text-center text-sm",
14
- role: "presentation",
15
- data: { command_target: "empty" },
16
- }
17
- end
11
+ def default_attrs
12
+ {
13
+ class: "py-6 text-center text-sm",
14
+ role: "presentation",
15
+ data: {command_target: "empty"}
16
+ }
18
17
  end
19
- end
18
+ end
19
+ end
@@ -1,41 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
4
- class Command::Group < Base
5
- def initialize(title: nil, **attrs)
6
- @title = title
7
- super(**attrs)
8
- end
4
+ class Command::Group < Base
5
+ def initialize(title: nil, **attrs)
6
+ @title = title
7
+ super(**attrs)
8
+ end
9
9
 
10
- def template(&block)
11
- div(**attrs) do
12
- render_header if @title
13
- render_items(&block)
14
- end
15
- end
10
+ def template(&block)
11
+ div(**attrs) do
12
+ render_header if @title
13
+ render_items(&block)
14
+ end
15
+ end
16
16
 
17
- private
17
+ private
18
18
 
19
- def render_header
20
- div(group_heading: @title) do
21
- @title
22
- end
23
- end
19
+ def render_header
20
+ div(group_heading: @title) do
21
+ @title
22
+ end
23
+ end
24
24
 
25
- def render_items(&block)
26
- div(group_items: "", role: "group", &block)
27
- end
25
+ def render_items(&block)
26
+ div(group_items: "", role: "group", &block)
27
+ end
28
28
 
29
- def default_attrs
30
- {
31
- class:
32
- "overflow-hidden p-1 text-foreground [&_[group-heading]]:px-2 [&_[group-heading]]:py-1.5 [&_[group-heading]]:text-xs [&_[group-heading]]:font-medium [&_[group-heading]]:text-muted-foreground",
33
- role: "presentation",
34
- data: {
35
- value: @title,
36
- command_target: "group",
37
- }
38
- }
39
- end
29
+ def default_attrs
30
+ {
31
+ class:
32
+ "overflow-hidden p-1 text-foreground [&_[group-heading]]:px-2 [&_[group-heading]]:py-1.5 [&_[group-heading]]:text-xs [&_[group-heading]]:font-medium [&_[group-heading]]:text-muted-foreground",
33
+ role: "presentation",
34
+ data: {
35
+ value: @title,
36
+ command_target: "group"
37
+ }
38
+ }
40
39
  end
41
- end
40
+ end
41
+ end
@@ -1,56 +1,56 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
4
- class Command::Input < Base
5
- def initialize(placeholder: "Type a command or search...", **attrs)
6
- @placeholder = placeholder
7
- super(**attrs)
8
- end
4
+ class Command::Input < Base
5
+ def initialize(placeholder: "Type a command or search...", **attrs)
6
+ @placeholder = placeholder
7
+ super(**attrs)
8
+ end
9
9
 
10
- def template
11
- input_container do
12
- search_icon
13
- input(**attrs)
14
- end
15
- end
10
+ def template
11
+ input_container do
12
+ search_icon
13
+ input(**attrs)
14
+ end
15
+ end
16
16
 
17
- private
17
+ private
18
18
 
19
- def search_icon
20
- svg(
21
- xmlns: "http://www.w3.org/2000/svg",
22
- viewbox: "0 0 20 20",
23
- fill: "currentColor",
24
- class: "w-4 h-4 mr-1.5"
25
- ) do |s|
26
- s.path(
27
- fill_rule: "evenodd",
28
- d:
29
- "M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z",
30
- clip_rule: "evenodd"
31
- )
32
- end
33
- end
19
+ def search_icon
20
+ svg(
21
+ xmlns: "http://www.w3.org/2000/svg",
22
+ viewbox: "0 0 20 20",
23
+ fill: "currentColor",
24
+ class: "w-4 h-4 mr-1.5"
25
+ ) do |s|
26
+ s.path(
27
+ fill_rule: "evenodd",
28
+ d:
29
+ "M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z",
30
+ clip_rule: "evenodd"
31
+ )
32
+ end
33
+ end
34
34
 
35
- def input_container(&block)
36
- div(class: "flex items-center border-b px-3", &block)
37
- end
35
+ def input_container(&block)
36
+ div(class: "flex items-center border-b px-3", &block)
37
+ end
38
38
 
39
- def default_attrs
40
- {
41
- class: "flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
42
- placeholder: @placeholder,
43
- data_action: "input->command#filter keydown.down->command#handleKeydown keydown.up->command#handleKeydown keydown.enter->command#handleKeydown keydown.esc->dismissable#dismiss",
44
- data_command_target: "input",
45
- autocomplete: "off",
46
- autocorrect: "off",
47
- spellcheck: false,
48
- autofocus: true,
49
- aria_autocomplete: "list",
50
- role: "combobox",
51
- aria_expanded: true,
52
- value: ""
53
- }
54
- end
39
+ def default_attrs
40
+ {
41
+ class: "flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
42
+ placeholder: @placeholder,
43
+ data_action: "input->command#filter keydown.down->command#handleKeydown keydown.up->command#handleKeydown keydown.enter->command#handleKeydown keydown.esc->dismissable#dismiss",
44
+ data_command_target: "input",
45
+ autocomplete: "off",
46
+ autocorrect: "off",
47
+ spellcheck: false,
48
+ autofocus: true,
49
+ aria_autocomplete: "list",
50
+ role: "combobox",
51
+ aria_expanded: true,
52
+ value: ""
53
+ }
55
54
  end
56
- end
55
+ end
56
+ end
@@ -1,31 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
4
- class Command::Item < Base
5
- def initialize(value:, text: "", href: "#", **attrs)
6
- @value = value
7
- @text = text
8
- @href = href
9
- super(**attrs)
10
- end
4
+ class Command::Item < Base
5
+ def initialize(value:, text: "", href: "#", **attrs)
6
+ @value = value
7
+ @text = text
8
+ @href = href
9
+ super(**attrs)
10
+ end
11
11
 
12
- def template(&block)
13
- a(**attrs, &block)
14
- end
12
+ def template(&block)
13
+ a(**attrs, &block)
14
+ end
15
15
 
16
- private
16
+ private
17
17
 
18
- def default_attrs
19
- {
20
- class: "relative flex cursor-pointer select-none items-center gap-x-2 rounded-sm px-2 py-1.5 text-sm outline-none hover:bg-accent hover:text-accent-foreground aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
21
- href: @href,
22
- role: "option",
23
- data: {
24
- command_target: "item",
25
- value: @value, text: @text
26
- },
27
- # aria_selected: "true", # Toggles aria-selected="true" on keydown
28
- }
29
- end
18
+ def default_attrs
19
+ {
20
+ class: "relative flex cursor-pointer select-none items-center gap-x-2 rounded-sm px-2 py-1.5 text-sm outline-none hover:bg-accent hover:text-accent-foreground aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
21
+ href: @href,
22
+ role: "option",
23
+ data: {
24
+ command_target: "item",
25
+ value: @value, text: @text
26
+ }
27
+ # aria_selected: "true", # Toggles aria-selected="true" on keydown
28
+ }
30
29
  end
31
- end
30
+ end
31
+ end
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
4
- class Command::List < Base
5
- def template(&block)
6
- div(**attrs, &block)
7
- end
4
+ class Command::List < Base
5
+ def template(&block)
6
+ div(**attrs, &block)
7
+ end
8
8
 
9
- private
9
+ private
10
10
 
11
- def default_attrs
12
- {
13
- class: "divide-y divide-border",
14
- }
15
- end
11
+ def default_attrs
12
+ {
13
+ class: "divide-y divide-border"
14
+ }
16
15
  end
17
- end
16
+ end
17
+ end
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PhlexUI
4
- class Command < Base
5
- def template(&block)
6
- div(**attrs, &block)
7
- end
4
+ class Command < Base
5
+ def template(&block)
6
+ div(**attrs, &block)
7
+ end
8
8
 
9
- private
9
+ private
10
10
 
11
- def default_attrs
12
- {
13
- data: { controller: "command" }
14
- }
15
- end
11
+ def default_attrs
12
+ {
13
+ data: {controller: "command"}
14
+ }
16
15
  end
17
- end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhlexUI
4
+ class Pagination::Content < Base
5
+ def template(&block)
6
+ ul(**attrs, &block)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ class: "flex flex-row items-center gap-1"
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhlexUI
4
+ class Pagination::Ellipsis < Base
5
+ def template(&block)
6
+ li do
7
+ span(**attrs) do
8
+ icon
9
+ span(class: "sr-only") { "More pages" }
10
+ end
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def icon
17
+ svg(
18
+ xmlns: "http://www.w3.org/2000/svg",
19
+ width: "24",
20
+ height: "24",
21
+ viewbox: "0 0 24 24",
22
+ fill: "none",
23
+ stroke: "currentColor",
24
+ stroke_width: "2",
25
+ stroke_linecap: "round",
26
+ stroke_linejoin: "round",
27
+ class: "h-4 w-4"
28
+ ) do |s|
29
+ s.circle(cx: "12", cy: "12", r: "1")
30
+ s.circle(cx: "19", cy: "12", r: "1")
31
+ s.circle(cx: "5", cy: "12", r: "1")
32
+ end
33
+ end
34
+
35
+ def default_attrs
36
+ {
37
+ aria: {hidden: true},
38
+ class: "flex h-9 w-9 items-center justify-center"
39
+ }
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhlexUI
4
+ class Pagination::Item < Base
5
+ def initialize(href: "#", active: false, **attrs)
6
+ @href = href
7
+ @active = active
8
+ super(**attrs)
9
+ end
10
+
11
+ def template(&block)
12
+ li do
13
+ a(href: @href, **attrs, &block)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def default_attrs
20
+ {
21
+ aria: {current: @active ? "page" : nil},
22
+ class: tokens(
23
+ PhlexUI::Button.new(variant: @active ? :outline : :ghost).attrs[:class]
24
+ )
25
+ }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PhlexUI
4
+ class Pagination < Base
5
+ def template(&block)
6
+ nav(**attrs, &block)
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ aria: {label: "pagination"},
14
+ class: "mx-auto flex w-full justify-center",
15
+ role: "navigation"
16
+ }
17
+ end
18
+ end
19
+ end