-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feat/select element #34
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
49e6094
fix: select element with base story
dannyk3941 a12ea4c
chore: clean up css and story controls
dannyk3941 8e9114b
chore: update components _index.scss for select
dannyk3941 090c20b
fix: review comments for story controls
dannyk3941 999b942
chore: remove control defaults
dannyk3941 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 104 additions & 0 deletions
104
packages/vanilla/src/components/select/select.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
export default { | ||
title: 'Patterns', | ||
parameters: { | ||
html: { | ||
root: '.cbp-form' | ||
} | ||
}, | ||
argTypes: { | ||
label: { | ||
name: 'Label', | ||
description: 'Represents a caption for the `<select>` element in the user interface.', | ||
control: { type: 'text' } | ||
}, | ||
inputDescription: { | ||
name: 'Description', | ||
description: 'Instructions or supplementary information regarding the `<select>` element.', | ||
control: { type: 'text' } | ||
}, | ||
inputId: { | ||
name: 'Input ID', | ||
description: 'The `id` on the native `select` tag, required to link the `label` and `select` for accessibility purposes.', | ||
control: { type: 'text' } | ||
}, | ||
formControlName: { | ||
name: 'Input Name', | ||
description: 'Name of the form control in the input element. Submitted with the form as part of a name/value pair.', | ||
control: { type: 'text' } | ||
}, | ||
errorMessage: { | ||
name: 'Error Message', | ||
description: 'A message in the input description that a problem has occurred.', | ||
control: { type: 'text' } | ||
}, | ||
optionsObj: { | ||
name: 'Options Object', | ||
description: 'Sets the label of the `<option>` and the `value` attribute.', | ||
control: { type: 'object' } | ||
}, | ||
disabled: { | ||
name: '`disabled` Attribute', | ||
description: 'Attribute that indicates that the user cannot interact with the control.', | ||
control: { type: 'boolean' } | ||
}, | ||
required: { | ||
name: '`required` Attribute', | ||
description: 'Indicates that the user must specify a value for the input before submission.', | ||
control: { type: 'boolean' } | ||
} | ||
}, | ||
decorators: [ | ||
(Story, context) => ` | ||
<form class="cbp-form"> | ||
<label for=${context.args.inputId} class="cbp-input__label">${context.args.label}</label> | ||
<p class="cbp-input__description" ${!context.args.required ? '' : 'hidden'}>${context.args.inputDescription}</p> | ||
<p class="cbp-input__description ${context.args.required ? 'cbp-input__description--error': ''}" ${context.args.required ? '' : 'hidden'}><i class="fas fa-exclamation-triangle"></i>${context.args.errorMessage}</p> | ||
${Story().outerHTML || Story()} | ||
</form> | ||
` | ||
] | ||
} | ||
|
||
const Template = ({ inputId, formControlName, disabled, required, optionsObj: { option1, option2, option3, option4, option5} }) => ( | ||
` | ||
<select class="cbp-input__select" name=${formControlName} id=${inputId} ${disabled ? 'disabled' : ''} ${required ? 'required' : ''} ${required ? 'aria-required="true"' : ''}> | ||
<option value="">-- Select --</option> | ||
<option value=${option1.value}>${option1.label}</option> | ||
<option value=${option2.value}>${option2.label}</option> | ||
<option value=${option3.value}>${option3.label}</option> | ||
<option value=${option4.value}>${option4.label}</option> | ||
<option value=${option5.value}>${option5.label}</option> | ||
</select> | ||
` | ||
) | ||
|
||
export const Select = Template.bind({}); | ||
Select.args = { | ||
label: 'Port of Departure', | ||
inputId: 'port', | ||
inputDescription: 'Required.', | ||
formControlName: 'departurePort', | ||
errorMessage: 'This field is required.', | ||
optionsObj: { | ||
option1: { | ||
value: 'baltimore', | ||
label: 'Port of Baltimore' | ||
}, | ||
option2: { | ||
value: 'boston', | ||
label: 'Port of Boston' | ||
}, | ||
option3: { | ||
value: 'philadelphia', | ||
label: 'Port of Philadelphia' | ||
}, | ||
option4: { | ||
value: 'washington', | ||
label: 'Port of Washington' | ||
}, | ||
option5: { | ||
value: 'zoolily', | ||
label: 'Port of Zoolily' | ||
}, | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
.cbp-input__select { | ||
appearance: none; | ||
background-color: var(--cbp-color-white); | ||
background-image: url('/assets/images/angle-arrow-down-gray-90.svg'); | ||
background-repeat: no-repeat; | ||
background-position: right var(--cbp-space-2x) center; | ||
background-size: var(--cbp-space-3x) var(--cbp-space-3x); | ||
border-color: var(--cbp-color-interactive-neutral-base); | ||
border-radius: var(--cbp-border-radius-soft); | ||
border-width: var(--cbp-border-size-md); | ||
color: var(--cbp-color-text-darkest); | ||
min-height: var(--cbp-space-9x); | ||
outline: 0; | ||
padding-left: var(--cbp-space-2x); | ||
width: 100%; | ||
|
||
&:hover { | ||
border-color: var(--cbp-color-base-neutral-darker); | ||
} | ||
|
||
&:focus { | ||
border-color: var(--cbp-color-interactive-focus-dark); | ||
} | ||
|
||
&:disabled { | ||
background-color: var(--cbp-color-interactive-disabled-light); | ||
border-color: var(--cbp-color-interactive-disabled-dark); | ||
font-style: italic; | ||
|
||
&:hover { | ||
border-color: var(--cbp-color-base-neutral-darker); | ||
} | ||
} | ||
|
||
&:invalid { | ||
background-color: var(--cbp-color-danger-lighter); | ||
border-color: var(--cbp-color-danger-dark); | ||
font-style: italic; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a
required
control that would set this. See my higher-level comment about this though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot this control, should be added now along with the
aria-required
attribute. Toggling this control will show the css of the:invalid
pseudo-class but regarding your comment below, we should revisit/discuss and finalize how to implement this along with the error message class.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm not sure why it would show the
:invalid
styling. Is this because you're still using therequired
attribute as well? This is certainly not desired behavior on an unfilled form and would be another reason not to userequired
.