-
Notifications
You must be signed in to change notification settings - Fork 166
login button component #9840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
login button component #9840
Changes from all commits
d9f619b
3fa9283
99639d8
21c0f36
84ae79e
d3adbe2
13a09c2
bb7afb8
1a37575
b78645a
c8dd0b2
3e04ff0
a9880c1
ce604e4
a381102
96a003d
3856e2d
22fd8cb
3692e6e
4398ecb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <%= content_tag( | ||
| :button, | ||
| **tag_options, | ||
| class: css_class, | ||
| ) do %> | ||
| Sign in with <%= content_tag(:span, APP_NAME, class: 'login-button__logo') %> | ||
| <% end %> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| class LoginButtonComponent < BaseComponent | ||
| VALID_COLORS = ['primary', 'primary-darker', 'primary-lighter'].freeze | ||
|
|
||
| attr_reader :color, :big, :tag_options | ||
|
|
||
| def initialize(color: 'primary', big: false, **tag_options) | ||
| if !VALID_COLORS.include?(color) | ||
| raise ArgumentError, "`color` #{color}} is invalid, expected one of #{VALID_COLORS}" | ||
| end | ||
|
|
||
| @big = big | ||
| @color = color | ||
nprimak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @tag_options = tag_options | ||
| end | ||
|
|
||
| def css_class | ||
| classes = ['usa-button', *tag_options[:class]] | ||
| classes << 'usa-button--big' if big | ||
nprimak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| classes << "login-button login-button--#{color}" | ||
| classes | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,52 @@ | ||||
| @use 'uswds-core' as *; | ||||
|
|
||||
| .login-button.usa-button--big > .login-button__logo { | ||||
| font-size: 1.8rem; | ||||
| margin-top: -2px; | ||||
| } | ||||
|
|
||||
| .login-button__logo { | ||||
| margin-left: 2px; | ||||
| font-size: 1.45rem; | ||||
| vertical-align: middle; | ||||
| color: transparent; | ||||
| background: no-repeat 100% url('logo.svg'); | ||||
|
|
||||
| .login-button--primary-darker & { | ||||
| background-image: url('logo-white.svg'); | ||||
| } | ||||
| } | ||||
|
|
||||
| .login-button.login-button--primary-lighter { | ||||
| @include u-bg('primary-lighter'); | ||||
| @include u-text('primary-darker'); | ||||
|
|
||||
| &:hover { | ||||
| @include u-bg('primary-lighter'); | ||||
|
||||
| "lint:css": "stylelint 'app/assets/stylesheets/**/*.scss' 'app/javascript/**/*.scss'", |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe LoginButtonComponent, type: :component do | ||
| include ActionView::Context | ||
| include ActionView::Helpers::TagHelper | ||
|
|
||
| let(:options) { {} } | ||
|
|
||
| subject(:rendered) do | ||
| render_inline LoginButtonComponent.new(**options) | ||
| end | ||
|
|
||
| it 'renders button text' do | ||
| expect(rendered).to have_text('Sign in with Login.gov') | ||
| end | ||
|
|
||
| it 'renders with design system classes and default color' do | ||
| expect(rendered).to have_css('button.usa-button.login-button.login-button--primary') | ||
| end | ||
|
|
||
| context 'as big' do | ||
| let(:options) { { big: true } } | ||
|
|
||
| it 'renders with design system classes' do | ||
| expect(rendered).to have_css('button.login-button.usa-button.usa-button--big') | ||
| end | ||
| end | ||
|
|
||
| context 'as darker color' do | ||
| let(:options) { { color: 'primary-darker' } } | ||
|
|
||
| it 'renders with design system classes' do | ||
| expect(rendered).to have_css('button.usa-button.login-button.login-button--primary-darker') | ||
| end | ||
| end | ||
|
|
||
| context 'as lighter color' do | ||
| let(:options) { { color: 'primary-lighter' } } | ||
|
|
||
| it 'renders with design system classes' do | ||
| expect(rendered).to have_css('button.usa-button.login-button.login-button--primary-lighter') | ||
| end | ||
| end | ||
|
|
||
| it 'raises error for unknown color' do | ||
| expect do | ||
| render_inline LoginButtonComponent.new(color: 'foo') | ||
| end.to raise_error(ArgumentError) | ||
| end | ||
|
|
||
| context 'with tag options' do | ||
| it 'renders as attributes' do | ||
| rendered = render_inline LoginButtonComponent.new( | ||
| type: :button, | ||
| class: 'my-custom-class', | ||
| data: { foo: 'bar' }, | ||
| ) | ||
|
|
||
| expect(rendered).to have_css('.usa-button.my-custom-class[type="button"][data-foo="bar"]') | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| class LoginButtonComponentPreview < ButtonComponentPreview | ||
| # @!group Preview | ||
| def default | ||
| render(LoginButtonComponent.new) | ||
| end | ||
|
|
||
| # @!endgroup | ||
|
|
||
| # @param big toggle | ||
| # @param color select [~,primary,primary-darker,primary-lighter] | ||
| def workbench( | ||
| big: false, | ||
| color: 'primary' | ||
| ) | ||
| render( | ||
| LoginButtonComponent.new( | ||
| big:, | ||
| color:, | ||
| ), | ||
| ) | ||
| end | ||
| end |
Uh oh!
There was an error while loading. Please reload this page.