Skip to content

Commit

Permalink
Merge pull request #183 from silinternational/develop
Browse files Browse the repository at this point in the history
Release 9.0.0
  • Loading branch information
hobbitronics authored Feb 8, 2023
2 parents b145e64 + 3df973d commit 64838b3
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 79 deletions.
36 changes: 22 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Reusable Svelte components for some internal applications

## installation

To install to your Svelte project, open your project's root directory in a terminal. Type or paste `npm i -D [email protected] [email protected] @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.
To install to your Svelte project, open your project's root directory in a terminal. Type or paste `npm i -D @silintl/ui-components` and press enter. 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 (I haven't figured out which versions require them). Paste in `npm i -D [email protected] [email protected]` and hit enter (versions will vary if you use an older release of this repo). You should already have svelte@3 installed if you are using this library.

If you are using typescript you will need to run `npm i -D tslib` to avoid a material-components-web type error.
If you are using typescript you will need to run `npm i -D tslib` to avoid a material-components-web type error. This will already be installed if you have set up SvelteKit with typescript using `npm create svelte@latest app-name`.

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
Expand Down Expand Up @@ -38,10 +38,10 @@ See https://google.github.io/material-design-icons/#sizing for sizing material i

## 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
If you are using an [MDC theme](https://material.io/develop/web/docs/theming) you may want to include a \_theme.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 material styling variables like --mdc-theme-primary --mdc-theme-secondary and other root variables to the App.svelte (your base +layout.svelte in sveltekit templates) file so they get applied to the ui-components.

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

Expand All @@ -63,11 +63,11 @@ and something similar to the following:
}
```

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 also valid.

## bundler configuration

Your Svelte project will need the bundler (rollup most likely) configured to compile Sass files. If you are using rollup your plugins in your "rollup.config.js" should look something like this taking special note of postcss and svelte:
SvelteKit won't need a bundler as it uses Vite, but Svelte projects will need a bundler (rollup or webpack most likely) configuration. If you are using rollup your plugins in your "rollup.config.js" should look something like this taking special note of postcss and svelte:

```
import postcss from 'rollup-plugin-postcss';
Expand Down Expand Up @@ -108,15 +108,21 @@ module.exports = {

## Sveltekit

Using this library in [Sveltekit](https://github.com/sveltejs/kit) is experimental (as of writing this Sveltekit is in release candidate phase).
You may get lots of source map source warnings as referenced [here](https://github.com/vitejs/vite/issues/2892) and it may take several seconds and/or refreshes for your app to start with `npm run dev`. Building and previewing your build should run smoothly. Below are a number of references that may be relevant to your experience:
Using this library in [Sveltekit](https://github.com/sveltejs/kit) is still experimental, but it seems to be working well.
Below are a number of issues that helped me get it working.

https://kit.svelte.dev/faq#packages

https://vitejs.dev/guide/dep-pre-bundling.html

https://vitejs.dev/guide/features.html#npm-dependency-resolving-and-pre-bundling

https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#what-is-going-on-with-vite-and-pre-bundling-dependencies

https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#prebundlesveltelibraries

https://github.com/vitejs/vite/issues/2892

https://github.com/sveltejs/kit/issues/885

## components
Expand All @@ -127,24 +133,26 @@ A list of all components and their props can be found in our running instance of

After installation and bundler configuration all of the components are ready to be imported.

Just include `import { Button } from '@silintl/ui-components'` (Sveltekit/Vite will need to use the full url) in your script section to import Button and any other components you want to use.
Just include `import { Button } from '@silintl/ui-components'` (~~Sveltekit/~~Vite only projects will need the full url: `import { Button } from '../../node_modules/@silintl/ui-components/index.mjs`
) in your script section to import Button and any other components you want to use.

## overriding default sass variables

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 );`

## examples
## examples and templates

See our Storybook [Docs](https://silinternational.github.io/ui-components/?path=/docs/example-introduction--page) for examples. Just click on the component you want to learn more about.

Here is a demo app with more examples of how to use components.
https://github.com/hobbitronics/svelte-ui-components-app
An opinionated Svelte template using rollup https://github.com/silinternational/the-way-svelte

A template using Vite https://github.com/hobbitronics/mikes-svelte-template

It was buit from https://github.com/sveltejs/template
A template using SvelteKit https://github.com/hobbitronics/sveltekit-ui-components

If you are building a single page app with routify then it is recommended to use this template https://github.com/roxiness/routify-starter
If you dont' want to use Sveltekit or the templates above and are building a single page app with routify then it is recommended to use this template https://github.com/roxiness/routify-starter (this library not pre-installed)

An example of using Button and Card:

Expand Down
2 changes: 1 addition & 1 deletion components/mdc/Menu/Menu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { onMount } from 'svelte'
export let menuItems = []
export let menuOpen = false
export let currentUrl = ''
let menu = {}
let element = {}
$: currentUrl = window.location.pathname
$: menu.open = menuOpen
onMount(() => {
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ declare module '@silintl/ui-components' {
interface MenuProps extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap['div']> {
menuItems?: MenuItem[]
menuOpen?: boolean
currentUrl?: string
}
export class Menu extends SvelteComponentTyped<MenuProps> {}

Expand Down
104 changes: 49 additions & 55 deletions package-lock.json

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

8 changes: 1 addition & 7 deletions stories/Card.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@ import { Meta, Template, Story } from '@storybook/addon-svelte-csf'
import { Button, Card } from '../components/mdc'
import { copyAndModifyArgs } from './helpers.js'
let title = 'Card'
const args = {
class: '', //will only work with global class
label: title,
}
</script>

<Meta title="Atoms/Card" component={Card} />

<Template let:args>
<Card {...args}>
{args.label}
</Card>
<Card {...args}>Card content</Card>
</Template>

<Story name="Default" {args} />
Expand All @@ -29,7 +24,6 @@ const args = {

<Story let:args name="actions">
<Card {...args}>
{title}
<p>Add optional actions with slot="actions" in the element you will put the actionable content.</p>
<span slot="actions">
<Button raised>button</Button>
Expand Down
6 changes: 4 additions & 2 deletions stories/Menu.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let content = 'Menu Button'
const args = {
class: 'dib relative opacity1', //for some reason the menu isn't behaving in storybook
menuOpen: true,
currentUrl: '/?path=/story/atoms-menu--primary',
menuItems: [
{
subtitle: 'Alerts',
Expand All @@ -15,16 +16,17 @@ const args = {
icon: 'notifications',
label: 'Alerts',
action: () => alert('Hello!'),
url: '/?path=/story/atoms-menu--primary',
},
{
icon: 'settings',
label: 'User settings',
url: '/household/settings',
url: '/',
},
{
icon: 'logout',
label: 'Sign out',
url: '/logout',
url: '/',
},
],
toggleMenu() {
Expand Down

0 comments on commit 64838b3

Please sign in to comment.