Skip to content

Commit

Permalink
Merge pull request #265 from silinternational/develop
Browse files Browse the repository at this point in the history
v11.3.0
  • Loading branch information
hobbitronics authored Apr 16, 2024
2 parents e960d3f + a857080 commit d6dbb77
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 20 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html), enforced with [semantic-release](https://github.com/semantic-release/semantic-release).

## [11.3.0](https://github.com/silinternational/ui-components/compare/v11.2.0...v11.3.0) (2024-04-16)


### Fixed

* **Select:** update to match installed version of material/select ([a739d35](https://github.com/silinternational/ui-components/commit/a739d35b5635c74f3846feb3cee3485e5db2929d))


### Added

* **Select:** Add Select.name for convenient form submission ([8f7380b](https://github.com/silinternational/ui-components/commit/8f7380bcd34df41600d3be7bbe9fafc3187c4df8))
* **Select:** Add Select.required prop ([94bab91](https://github.com/silinternational/ui-components/commit/94bab918ba3a6560c49670622802aa942ee32628))
* **Select:** Add Select.ShowError prop which applies the mdc-select--invalid class to the ([3d8f95d](https://github.com/silinternational/ui-components/commit/3d8f95d4657a1ee99f6900522a3449126790f20e))


## [11.2.0](https://github.com/silinternational/ui-components/compare/v11.1.2...v11.2.0) (2024-04-09)


Expand Down
42 changes: 30 additions & 12 deletions components/mdc/Select/Select.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export let width = '280px'
export let disabled = false
/** @type {string} The ID of the selected option. */
export let selectedID = ''
/** @type {boolean} makes a selection required and adds invalid class when none selected */
export let required = false
/** @type {boolean} applies the mdc-select--invalid class */
export let showError = false
/** @type {string} a name for the hidden input field for form submission*/
export let name = ''
const dispatch = createEventDispatcher()
const labelID = generateRandomID('select-label-')
Expand Down Expand Up @@ -61,13 +67,32 @@ afterUpdate(() => {
})
</script>

<div class="mdc-select mdc-select--outlined {$$props.class || ''}" bind:this={element} style="width: {width}">
<div class="mdc-select__anchor" role="button" aria-haspopup="listbox" aria-labelledby="{labelID} {selectedTextID}">
<div
class="mdc-select mdc-select--outlined {$$props.class || ''}"
class:mdc-select--required={required}
class:mdc-select--invalid={showError}
bind:this={element}
style="width: {width}"
>
<input {required} type="hidden" {name} />
<div
class="mdc-select__anchor"
aria-required={required}
aria-haspopup="listbox"
aria-labelledby="{labelID} {selectedTextID}"
>
<span class="mdc-notched-outline">
<span class="mdc-notched-outline__leading" />
<span class="mdc-notched-outline__notch">
<span id={labelID} class="mdc-floating-label">{label}</span>
</span>
<span class="mdc-notched-outline__trailing" />
</span>
<span class="mdc-select__selected-text-container">
<span id={selectedTextID} class="mdc-select__selected-text" />
</span>
<span class="mdc-select__dropdown-icon">
<svg class="mdc-select__dropdown-icon-graphic" viewBox="7 10 10 5">
<svg class="mdc-select__dropdown-icon-graphic" viewBox="7 10 10 5" focusable="false">
<polygon
class="mdc-select__dropdown-icon-inactive"
stroke="none"
Expand All @@ -77,17 +102,10 @@ afterUpdate(() => {
<polygon class="mdc-select__dropdown-icon-active" stroke="none" fill-rule="evenodd" points="7 15 12 10 17 15" />
</svg>
</span>
<span class="mdc-notched-outline">
<span class="mdc-notched-outline__leading" />
<span class="mdc-notched-outline__notch">
<span id={labelID} class="mdc-floating-label">{label}</span>
</span>
<span class="mdc-notched-outline__trailing" />
</span>
</div>

<div class="mdc-select__menu mdc-menu mdc-menu-surface" style="width: {width}" role="listbox">
<ul class="mdc-deprecated-list">
<div class="mdc-select__menu mdc-menu mdc-menu-surface mdc-menu-surface--fullwidth">
<ul class="mdc-deprecated-list" role="listbox" aria-label={label + ' picker listbox'}>
{#each options as { id, name } (id)}
<li class="mdc-deprecated-list-item" data-value={id} role="option" aria-selected={isOptionSelected(id)}>
<span class="mdc-deprecated-list-item__text">{name}</span>
Expand Down
2 changes: 1 addition & 1 deletion components/mdc/Select/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
@use '@material/select/styles';

/* MDC select floating label */
.mdc-select:not(.mdc-select--disabled).mdc-select--focused .mdc-floating-label {
.mdc-select:not(.mdc-select--disabled, .mdc-select--invalid).mdc-select--focused .mdc-floating-label {
color: var(--mdc-theme-primary);
}
7 changes: 5 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,14 @@ declare module '@silintl/ui-components' {
}

interface SelectProps {
disabled?: boolean
label?: string
name?: string
options?: { name: string; id: string }[]
width?: string
disabled?: boolean
required?: boolean
showError?: boolean
selectedID?: string
width?: string
class?: string
}
export class Select extends SvelteComponentTyped<SelectProps> {}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@silintl/ui-components",
"version": "11.2.0",
"version": "11.3.0",
"description": "Reusable Svelte components for some internal applications",
"main": "index.mjs",
"module": "index.mjs",
Expand Down
20 changes: 18 additions & 2 deletions stories/Select.stories.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script>
import { Meta, Template, Story } from '@storybook/addon-svelte-csf'
import { Select } from '../components/mdc'
import { Button, Select, Snackbar, setNotice } from '../components/mdc'
import { copyAndModifyArgs } from './helpers.js'
import { Form } from '../components/custom'
const args = {
options: [
Expand All @@ -21,13 +22,28 @@ const args = {
<Meta title="Atoms/Select" component={Select} />

<Template let:args>
<Select {...args} on:change={args['on:change']} on:populated={args['on:populated']} />
<Form on:submit={(e) => setNotice('submitted')}>
<p>
<Select {...args} on:change={args['on:change']} on:populated={args['on:populated']} />
</p>
<Button raised>Submit</Button>
</Form>

<Snackbar />
</Template>

<Story name="Default" {args} />

<Story name="selectedID" args={copyAndModifyArgs(args, { selectedID: '5' })} />

<Story name="Label" args={copyAndModifyArgs(args, { label: 'Label' })} />

<Story name="Width" args={copyAndModifyArgs(args, { width: '560px' })} />

<Story name="Disabled" args={copyAndModifyArgs(args, { disabled: true })} />

<Story name="required" args={copyAndModifyArgs(args, { required: true })} />

<Story name="showError" args={copyAndModifyArgs(args, { showError: true })} />

<Story name="name" args={copyAndModifyArgs(args, { name: 'category' })} />

0 comments on commit d6dbb77

Please sign in to comment.