Skip to content

Commit

Permalink
Merge pull request #141 from silinternational/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
hobbitronics authored Apr 28, 2022
2 parents f5f82de + 777de38 commit 5196463
Show file tree
Hide file tree
Showing 27 changed files with 2,438 additions and 2,689 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ Reusable Svelte components for some internal applications

## installation

To install to your Svelte project, open your project's root directory in a terminal. Type `npm i @silintl/ui-components --save-dev` and press enter. You may also have to run `npm i material-components-web@10.0.0 --save-dev` and possibly `npm i [email protected] --save-dev` to get sass stuff working if it doesn't work initially or you want to develop additional material web components in your app. It may depend on your version of npm if this is necessary. You should already have svelte@3 installed if you are using this library.
To install to your Svelte project, open your project's root directory in a terminal. Type or paste `npm i -D [email protected] material-components-web@13.0.0 @silintl/ui-components` and press enter (versions will vary if you use an older release of this repo). Sass and-material-components web are required to develop additional material web components in your app, but it may depend on your version of npm if they are necessary even if you don't. You should already have svelte@3 installed if you are using this library. If you are using typescript you will probaly need to run `npm i -D tslib` to avoid a material-components-web type error.

You will also want to follow the example below for your index.html (app.html for sveltekit templates) for Material Icons to work and for Google fonts to load.
see https://github.com/material-components/material-web#2-write-html-and-javascript

Your index.html could look something like this

```
<!doctype html>
<html>
Expand All @@ -27,35 +28,40 @@ Your index.html could look something like this
<link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet">
</head>
...
```
```

See `theming` and `typography` for more details on how to configure fonts and themes.

See https://google.github.io/material-design-icons/#sizing for sizing material icons.

## theming

If you are using an [MDC theme](https://material.io/develop/web/docs/theming) you may want to include a _typography.scss file and import it into
_index.scss.
If you are using an [MDC theme](https://material.io/develop/web/docs/theming) you may want to include a \_typography.scss file and import it into
\_index.scss.

Import _index.scss or other file(s) that contains stuff like --mdc-theme-primary --mdc-theme-secondary and other root variables to the App.svelte (Index.svelte in sveltekit templates) or Index.html (App.html for sveltekit) file (unless they are being declared there already) so they get applied to the ui-components.
Import \_index.scss or other file(s) that contains stuff like --mdc-theme-primary --mdc-theme-secondary and other root variables to the App.svelte (Index.svelte in sveltekit templates) or Index.html (App.html for sveltekit) file (unless they are being declared there already) so they get applied to the ui-components.

See https://github.com/silinternational/ui-components/blob/develop/stories/_theme.scss for exposed theme properties.

## typography

See [typography](https://material.io/develop/web/components/typography)

In your _typography.scss or similar file include the following snippet:
In your \_typography.scss or similar file include the following snippet:

```
@use '@material/typography/mdc-typography';
```

and something similar to the following:

```
:root {
--mdc-typography-font-family: Source Sans Pro, Roboto, sans-serif;
}
```
and then import it to your sass entry point like _index.scss. You may prefer to declare your root typography rules elsewhere (eg. index.html) which is ok.

and then import it to your sass entry point like \_index.scss. You may prefer to declare your root typography rules elsewhere (eg. index.html) which is ok.

## bundler configuration

Expand Down Expand Up @@ -112,9 +118,7 @@ Just include `import { Button } from '@silintl/ui-components'` in your script se

In your main sass file just use the following pattern to override any sass variables. See https://github.com/silinternational/ui-components/blob/develop/stories/_index.scss for exposed sass variables.

`@use './components/mdc/Button' with (
$radius: 16px
);`
`@use './components/mdc/Button' with ( $radius: 16px );`

## examples

Expand Down Expand Up @@ -195,4 +199,4 @@ Classes from [global.scss](https://github.com/silinternational/ui-components/blo

## contributions

All commit messages must follow [Angular Commit Message Conventions](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-format) for a release to be triggered upon merging to main. Here is a basic example: `feat(pencil): add 'graphiteWidth' option`. This will trigger a minor release. If this is not done, an empty commit with the proper format can be pushed to trigger the release. See https://github.com/semantic-release/semantic-release for more details. Semantic Release will also update the version and the CHANGELOG based on the commit messages.
All commit messages must follow [Angular Commit Message Conventions](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-format) for a release to be triggered upon merging to main. Here is a basic example: `feat(pencil): add 'graphiteWidth' option`. This will trigger a minor release. If this is not done, an empty commit with the proper format can be pushed to trigger the release. See https://github.com/semantic-release/semantic-release for more details. Semantic Release will also update the version and the CHANGELOG based on the commit messages.
91 changes: 91 additions & 0 deletions components/custom/SearchableSelect/SearchableSelect.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<script>
import { generateRandomID } from '../../../random'
import { createEventDispatcher } from 'svelte'
export let options = {}
export let choice = ''
export let placeholder = ''
export let padding = '12px'
export let width = '232px'
export let maxlength = 255
export let disabled = false
let element = {}
let randomId = generateRandomID('dataList-')
$: internalChoice = choice
const dispatch = createEventDispatcher()
const onChange = () => {
options[internalChoice] && dispatch('chosen', options[internalChoice])
choice = internalChoice
element.blur()
}
</script>

<style>
*,
*::before,
*::after {
box-sizing: border-box;
}
.custom-field {
font-size: 14px;
position: relative;
border-top: 20px solid transparent;
}
.custom-field input {
border-radius: 8px;
border: 1px solid gray;
padding: var(--field-padding) 0 var(--field-padding) var(--field-padding);
}
.custom-field .placeholder {
position: absolute;
bottom: -52px;
top: 23px;
transform: translateY(-50%);
color: #aaa;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
left: var(--field-padding);
width: calc(100% - (var(--field-padding) * 2));
transition: top 0.3s ease, color 0.3s ease, font-size 0.3s ease;
}
.custom-field input:not(:placeholder-shown) + .placeholder,
.custom-field input:focus + .placeholder {
top: 3px;
font-size: 10px;
color: #222;
}
</style>

<label class="custom-field" style="--field-padding: {padding}; {$$props.class}">
<input
autocomplete="off"
{disabled}
{maxlength}
class="fs-14 {$$props.class}"
style="width: {width}"
list={randomId}
placeholder="&nbsp;"
bind:this={element}
bind:value={internalChoice}
on:change={onChange}
on:blur={() => dispatch('check', internalChoice)}
on:focus={() => (internalChoice = '')}
/>
<span class="placeholder">{placeholder}</span>
</label>

<datalist id={randomId}>
{#each Object.keys(options) as option}
<option value={option} />
{/each}
</datalist>
3 changes: 3 additions & 0 deletions components/custom/SearchableSelect/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import SearchableSelect from './SearchableSelect.svelte'

export default SearchableSelect
3 changes: 2 additions & 1 deletion components/custom/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Badge from './Badge'
import Form from './Form'
import StaticChip from './StaticChip'
import SearchableSelect from './SearchableSelect'

export { Badge, Form, StaticChip }
export { Badge, Form, SearchableSelect, StaticChip }
8 changes: 8 additions & 0 deletions components/mdc/Dialog/Alert.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ onMount(() => {
})
</script>

<style>
i.material-icons {
position: relative;
top: 4px;
color: var(--mdc-theme-icon-color);
}
</style>

<div class="mdc-dialog" bind:this={element}>
<div class="mdc-dialog__container">
<div
Expand Down
20 changes: 10 additions & 10 deletions components/mdc/Drawer/Drawer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ main {
}
/* TODO: keep an eye on this bug https://github.com/material-components/material-components-web/issues/5242, overriding for now so menu items will take on the themed color */
.mdc-drawer .mdc-list-item--activated,
.mdc-drawer .mdc-list-item--activated .mdc-list-item__graphic {
.mdc-drawer .mdc-deprecated-list-item--activated,
.mdc-drawer .mdc-deprecated-list-item--activated .mdc-deprecated-list-item__graphic {
color: var(--mdc-theme-primary-variant, var(--mdc-theme-primary));
}
.mdc-list-item {
.mdc-deprecated-list-item {
margin: 4px 8px;
}
.main-content-height {
Expand All @@ -124,7 +124,7 @@ main {
<slot name="drawer-content-top" />
<!-- override built-in padding so height 100 works correctly without creating a vertical scroller -->
<!-- changing the list to flex causes the margins to not collapse -->
<nav class="mdc-list flex column p-0" class:h-100={isFullHeightMenu} on:click={onListClick} bind:this={listElement}>
<nav class="mdc-deprecated-listflex column p-0" class:h-100={isFullHeightMenu} on:click={onListClick} bind:this={listElement}>
{#each menuItems as { icon, label, url, urlPattern, hide, button, tooltip }, i}
{#if label === '--break--'}
<span class="grow-1" />
Expand All @@ -136,23 +136,23 @@ main {
<IconButton class="mdc-theme--primary pl-1" {icon} ariaLabel={label} {url} />
{:else if url}
<a
class="mdc-list-item"
class:mdc-list-item--activated={isMenuItemActive(currentUrl, url, urlPattern)}
class="mdc-deprecated-list-item"
class:mdc-deprecated-list-item--activated={isMenuItemActive(currentUrl, url, urlPattern)}
href={url}
aria-current={isMenuItemActive(currentUrl, url, urlPattern) ? 'page' : null}
tabindex={i === 0 ? 0 : undefined}
>
<span class="mdc-list-item__ripple" />
<span class="mdc-deprecated-list-item__ripple" />
{#if icon}
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">{icon}</i>
<i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">{icon}</i>
{/if}

{#if label && isNotMini}
<span class="mdc-list-item__text">{label}</span>
<span class="mdc-deprecated-list-item__text">{label}</span>
{/if}
</a>
{:else}
<hr class="mdc-list-divider mdc-list-divider--inset-leading mdc-list-divider--inset-trailing" />
<hr class="mdc-deprecated-list-divider mdc-deprecated-list-divider--inset-leading mdc-deprecated-list-divider--inset-trailing" />
{/if}
</Tooltip.Wrapper>
{#if tooltip}
Expand Down
2 changes: 1 addition & 1 deletion components/mdc/Drawer/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@include drawer.core-styles;
@include drawer.dismissible-core-styles;
@include drawer.modal-core-styles;
@include list.core-styles;
@include list.deprecated-core-styles;

.border-white {
@include drawer.border-color(#fff);
Expand Down
14 changes: 10 additions & 4 deletions components/mdc/IconButton/IconButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ onMount(() => {
on:mousedown
on:blur
on:focus
bind:this={element}>{icon}</a
>
bind:this={element}>
<div class="mdc-icon-button__ripple"></div>
<span class="mdc-icon-button__focus-ring"></span>
{icon}
</a>
{:else}
<button
class="mdc-icon-button material-icons {$$props.class}"
Expand All @@ -40,6 +43,9 @@ onMount(() => {
on:mousedown
on:blur
on:focus
bind:this={element}>{icon}</button
>
bind:this={element}>
<div class="mdc-icon-button__ripple"></div>
<span class="mdc-icon-button__focus-ring"></span>
{icon}
</button>
{/if}
4 changes: 1 addition & 3 deletions components/mdc/IconButton/_index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
@use '@material/icon-button';

@include icon-button.core-styles;
@use '@material/icon-button/styles';
2 changes: 1 addition & 1 deletion components/mdc/List/Divider.svelte
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<li role="separator" class="mdc-list-divider" />
<li role="separator" class="mdc-deprecated-list-divider" />
22 changes: 11 additions & 11 deletions components/mdc/List/Item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,39 @@ img {

<li
bind:this={element}
class="mdc-list-item"
class:mdc-list-item--activated={activated}
class:mdc-list-item--disabled={nonInteractive}
class="mdc-deprecated-list-item"
class:mdc-deprecated-list-item--activated={activated}
class:mdc-deprecated-list-item--disabled={nonInteractive}
data-mdc-dialog-action={$$props['data-mdc-dialog-action']}
on:click
{tabindex}
>
{#if graphicURL}
<div class="mdc-list-item__graphic">
<div class="mdc-deprecated-list-item__graphic">
<img class="br-50" alt={graphicAlt} src={graphicURL} />
</div>
{:else if icon}
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">{icon}</i>
<i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">{icon}</i>
{/if}

<span class="mdc-list-item__ripple" />
<span class="mdc-deprecated-list-item__ripple" />

<span class="mdc-list-item__text" class:nonInteractive>
<span class="mdc-deprecated-list-item__text" class:nonInteractive>
{#if primary || secondary}
<span class="mdc-list-item__primary-text">{primary}</span>
<span class="mdc-list-item__secondary-text">{secondary}</span>
<span class="mdc-deprecated-list-item__primary-text">{primary}</span>
<span class="mdc-deprecated-list-item__secondary-text">{secondary}</span>
{:else}
{text}
<slot />
{/if}
</span>

<div class="mdc-list-item__meta">
<div class="mdc-deprecated-list-item__meta">
{meta}
<slot name="meta" />
</div>
</li>

{#if withDivider}
<li role="separator" class="mdc-list-divider" />
<li role="separator" class="mdc-deprecated-list-divider" />
{/if}
6 changes: 3 additions & 3 deletions components/mdc/List/List.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ ul {
</style>

<ul
class="mdc-list {$$props.class}"
class:mdc-list--two-line={twoLine}
class:mdc-list--avatar-list={avatar}
class="mdc-deprecated-list {$$props.class}"
class:mdc-deprecated-list--two-line={twoLine}
class:mdc-deprecated-list--avatar-list={avatar}
bind:this={element}
>
<slot />
Expand Down
2 changes: 1 addition & 1 deletion components/mdc/List/_index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@use '@material/list';

@include list.core-styles;
@include list.deprecated-core-styles;
Loading

0 comments on commit 5196463

Please sign in to comment.