Skip to content

Commit

Permalink
fix preview issues and set a class for text so it can be truncated wh…
Browse files Browse the repository at this point in the history
…en it is too long
  • Loading branch information
bsatarnejad committed Jan 6, 2025
1 parent 1bbaa39 commit 472b01b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 28 deletions.
7 changes: 0 additions & 7 deletions app/components/primer/alpha/text_field.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,8 @@
color: var(--fgColor-muted);
pointer-events: none;
&:has( .FormControl-input-trailingVisualText) {
width: auto;
max-width: 25%;
padding-left: var(--base-size-8);

& .FormControl-input-trailingVisualText {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
}
/* TODO: replace with new Button component */
Expand Down
13 changes: 1 addition & 12 deletions app/lib/primer/forms/dsl/text_field_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(name:, label:, **system_arguments)

@show_clear_button = system_arguments.delete(:show_clear_button)
@leading_visual = system_arguments.delete(:leading_visual)
@trailing_visual = build_trailing_visual(system_arguments.delete(:trailing_visual))
@trailing_visual = system_arguments.delete(:trailing_visual)
@leading_spinner = !!system_arguments.delete(:leading_spinner)
@clear_button_id = system_arguments.delete(:clear_button_id)
@inset = system_arguments.delete(:inset)
Expand Down Expand Up @@ -55,17 +55,6 @@ def leading_visual?
!!@leading_visual
end

def build_trailing_visual(trailing_visual)
return nil unless trailing_visual

icon = trailing_visual[:icon]
text = trailing_visual[:text]
counter = trailing_visual[:counter]
label = trailing_visual[:label]

{ icon: icon, text: text, counter: counter, label: label }.compact
end

def to_component
TextField.new(input: self)
end
Expand Down
4 changes: 2 additions & 2 deletions app/lib/primer/forms/text_field.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<%= render(Primer::Beta::Octicon.new(icon: :"x-circle-fill")) %>
</button>
<% end %>
<% if (component = @input.trailing_visual_component) %>
<% if @input.trailing_visual %>
<div class="FormControl-input-trailingVisualWrap">
<%= render(component) %>
<%= render(trailing_visual_component) %>
</div>
<% end %>
<% end %>
Expand Down
8 changes: 5 additions & 3 deletions app/lib/primer/forms/text_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ def trailing_visual_component
"FormControl-input-trailingVisualCounter"
)

Primer::Beta::Counter.new(**counter_arguments))
Primer::Beta::Counter.new(**counter_arguments)
elsif (truncate_arguments = visual[:text])
# Render text if specified
truncate_arguments[:classes] = class_names(
truncate_arguments.delete(:classes),
"FormControl-input-trailingVisualText"
)
text = truncate_arguments.delete(:text)
Primer::Beta::Truncate.new(**truncate_arguments).with_content(text)
end
end


end
end
end
14 changes: 10 additions & 4 deletions previews/primer/alpha/text_field_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,25 +175,31 @@ def monospace
# @label With trailing icon
# @snapshot
def with_trailing_icon
render(Primer::Alpha::TextField.new(trailing_visual: { icon: :search }, name: "my-text-field", label: "My text field"))
render(Primer::Alpha::TextField.new(trailing_visual: { icon: { icon: :search } }, name: "my-text-field", label: "My text field"))
end

# @label With trailing text
# @snapshot
def with_trailing_text
render(Primer::Alpha::TextField.new( trailing_visual: { text: "minute" }, name: "my-text-field", label: "My text field"))
render(Primer::Alpha::TextField.new( trailing_visual: { text: { text: "minute" } }, name: "my-text-field", label: "My text field"))
end

# @label With trailing long text
# @snapshot
def with_trailing_long_text
render(Primer::Alpha::TextField.new( trailing_visual: { text: { text: "Long trailing text" } }, name: "my-text-field", label: "My text field"))
end

# @label With trailing counter
# @snapshot
def with_trailing_counter
render(Primer::Alpha::TextField.new( trailing_visual: { counter: 5 }, name: "my-text-field", label: "My text field"))
render(Primer::Alpha::TextField.new( trailing_visual: { counter: { counter: 5 } }, name: "my-text-field", label: "My text field"))
end

# @label With trailing label
# @snapshot
def with_trailing_label
render(Primer::Alpha::TextField.new( trailing_visual: { label: "Hello" }, name: "my-text-field", label: "My text field"))
render(Primer::Alpha::TextField.new( trailing_visual: { label: { text: "Hello" } }, name: "my-text-field", label: "My text field"))
end

# @label With leading visual
Expand Down

0 comments on commit 472b01b

Please sign in to comment.