Skip to content

Commit dadc645

Browse files
authored
Merge pull request #123 from silinternational/feature/remove-routify
Remove routify
2 parents 08b09de + 2247b8c commit dadc645

File tree

9 files changed

+115
-934
lines changed

9 files changed

+115
-934
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Reusable Svelte components for some internal applications
44

55
## installation
66

7-
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.
7+
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 [email protected] --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.
88

99
## bundler configuration
1010

@@ -144,7 +144,7 @@ Classes from [global.scss](https://github.com/silinternational/ui-components/blo
144144

145145
## theming
146146

147-
If you are using an [MDC theme](https://material.io/develop/web/docs/theming) and [typography](https://material.io/develop/web/components/typography) then import your \_index.scss file to the App.svelte 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.
147+
If you are using an [MDC theme](https://material.io/develop/web/docs/theming) and [typography](https://material.io/develop/web/components/typography) then import your _index.scss or other file(s) that contains stuff like --mdc-theme-primary --mdc-theme-secondary, --mdc-typography-font-family, etc and other root variables to the App.svelte or Index.html file (unless they are in those files 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.
148148

149149
## contributions
150150

components/Tour.svelte

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script>
22
import { Dialog } from '../components/mdc'
33
import { onMount, tick } from 'svelte'
4-
import { goto } from '@roxi/routify'
54
65
export let steps = []
76
export let data = {}
@@ -13,6 +12,8 @@ let tourMessage = '' // tour message can accept html markup -- use caution to no
1312
let target = ''
1413
let buttons = []
1514
15+
let anchorEl = {}
16+
1617
$: setAlertProps(step, data)
1718
1819
onMount(() => {
@@ -26,7 +27,8 @@ async function alertChosen(choice) {
2627
2728
if (choice === 'discard') {
2829
if (target) {
29-
$goto(target)
30+
anchorEl.href = target
31+
anchorEl.click()
3032
return
3133
}
3234
step++
@@ -75,3 +77,4 @@ function setAlertProps() {
7577
open={openDialog}
7678
{buttons}>{@html tourMessage}</Dialog.Alert
7779
>
80+
<a bind:this={anchorEl} href="/"><span /></a>

components/mdc/Drawer/Drawer.svelte

+2-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { MDCList } from '@material/list'
66
import Button from '../Button'
77
import IconButton from '../IconButton/IconButton.svelte'
88
import Tooltip from '../Tooltip/Tooltip.svelte'
9-
import { beforeUrlChange, goto } from '@roxi/routify'
109
import { onMount } from 'svelte'
1110
import TopAppBar from '../TopAppBar'
1211
@@ -21,6 +20,7 @@ export let isFullHeightMenu = false
2120
export let miniMenu = false
2221
export let modal = false
2322
export let toggle = false
23+
export let currentUrl = ''
2424
2525
let mdcDrawer = {}
2626
let mdcList = {}
@@ -50,15 +50,8 @@ const isMenuItemActive = (currentUrl, menuItemUrl, urlPattern) => {
5050
return currentUrl === menuItemUrl || (urlPattern && RegExp(urlPattern).test(currentUrl))
5151
}
5252
53-
$: currentUrl = window.location.pathname
5453
$: toggle, toggleDrawer()
5554
56-
$beforeUrlChange(({ url }) => {
57-
currentUrl = url
58-
59-
return true
60-
})
61-
6255
const showAppropriateThings = () => {
6356
showAppropriateDrawer()
6457
showAppropriateSizeMenu()
@@ -140,7 +133,7 @@ main {
140133
{#if button && isNotMini}
141134
<Button class="m-1" raised prependIcon={icon} {url}>{label}</Button>
142135
{:else if button}
143-
<IconButton class="mdc-theme--primary pl-1" {icon} ariaLabel={label} on:click={() => $goto(url)} />
136+
<IconButton class="mdc-theme--primary pl-1" {icon} ariaLabel={label} {url} />
144137
{:else if url}
145138
<a
146139
class="mdc-list-item"

components/mdc/IconButton/IconButton.svelte

+27-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { onMount } from 'svelte'
55
66
export let icon
77
export let ariaLabel
8+
export let url = ''
9+
export let disabled = false
810
911
let element = {}
1012
onMount(() => {
@@ -16,6 +18,28 @@ onMount(() => {
1618
})
1719
</script>
1820

19-
<button class="mdc-icon-button material-icons {$$props.class}" aria-label={ariaLabel} on:click bind:this={element}
20-
>{icon}</button
21-
>
21+
{#if url}
22+
<a
23+
href={url}
24+
role="button"
25+
class="mdc-icon-button material-icons {$$props.class}"
26+
aria-label={ariaLabel}
27+
{disabled}
28+
on:click
29+
on:mousedown
30+
on:blur
31+
on:focus
32+
bind:this={element}>{icon}</a
33+
>
34+
{:else}
35+
<button
36+
class="mdc-icon-button material-icons {$$props.class}"
37+
aria-label={ariaLabel}
38+
{disabled}
39+
on:click
40+
on:mousedown
41+
on:blur
42+
on:focus
43+
bind:this={element}>{icon}</button
44+
>
45+
{/if}

components/mdc/Menu/Menu.svelte

+39-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<!-- https://github.com/material-components/material-components-web/tree/master/packages/mdc-menu -->
22
<script>
33
import { MDCMenu } from '@material/menu'
4-
import { goto } from '@roxi/routify'
54
import { onMount } from 'svelte'
65
76
export let menuItems = []
@@ -22,14 +21,12 @@ onMount(() => {
2221
})
2322
2423
const isMenuItemActive = (currentUrl, menuItemUrl) => currentUrl === menuItemUrl
25-
const handleItemClick = (url, action) => {
26-
if (url) {
27-
$goto(url)
28-
} else if (typeof action === 'function') {
24+
const handleItemClick = (action) => {
25+
if (typeof action === 'function') {
2926
action()
3027
}
3128
}
32-
const handleItemKeydown = (e, url, action) => (e.code == 'Space' || e.code == 'Enter') && handleItemClick(url, action)
29+
const handleItemKeydown = (e, action) => (e.code == 'Space' || e.code == 'Enter') && handleItemClick(action)
3330
const closeMenuHandler = () => {
3431
if (!menu.open) {
3532
//checks to make sure the click wasn't opening the menu or on the menu
@@ -45,24 +42,42 @@ const closeMenuHandler = () => {
4542
<ul class="mdc-list" role="menu" aria-hidden="true" aria-orientation="vertical" tabindex="-1">
4643
{#each menuItems as { icon, label, url, action }, i}
4744
<!-- svelte-ignore a11y-invalid-attribute -->
48-
<li
49-
on:click|preventDefault={() => handleItemClick(url, action)}
50-
on:keydown|preventDefault={(e) => handleItemKeydown(e, url, action)}
51-
role="menuitem"
52-
class="mdc-list-item"
53-
class:mdc-list-item--activated={isMenuItemActive(currentUrl, url)}
54-
aria-current={isMenuItemActive(currentUrl, url) ? 'page' : null}
55-
tabindex={i === 0 ? 0 : undefined}
56-
on:blur={closeMenuHandler}
57-
>
58-
<span class="mdc-list-item__ripple" />
59-
{#if icon}
60-
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">{icon}</i>
61-
{/if}
62-
{#if label}
63-
<span class="mdc-list-item__text">{label}</span>
64-
{/if}
65-
</li>
45+
{#if url}
46+
<a
47+
href={url}
48+
role="menuitem"
49+
class="mdc-list-item"
50+
class:mdc-list-item--activated={isMenuItemActive(currentUrl, url)}
51+
aria-current={isMenuItemActive(currentUrl, url) ? 'page' : null}
52+
tabindex={i === 0 ? 0 : undefined}
53+
on:blur={closeMenuHandler}
54+
>
55+
<span class="mdc-list-item__ripple" />
56+
{#if icon}
57+
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">{icon}</i>
58+
{/if}
59+
{#if label}
60+
<span class="mdc-list-item__text">{label}</span>
61+
{/if}
62+
</a>
63+
{:else}
64+
<li
65+
on:click|preventDefault={() => handleItemClick(action)}
66+
on:keydown|preventDefault={(e) => handleItemKeydown(e, action)}
67+
role="menuitem"
68+
class="mdc-list-item"
69+
tabindex={i === 0 ? 0 : undefined}
70+
on:blur={closeMenuHandler}
71+
>
72+
<span class="mdc-list-item__ripple" />
73+
{#if icon}
74+
<i class="material-icons mdc-list-item__graphic" aria-hidden="true">{icon}</i>
75+
{/if}
76+
{#if label}
77+
<span class="mdc-list-item__text">{label}</span>
78+
{/if}
79+
</li>
80+
{/if}
6681
{/each}
6782
</ul>
6883
</div>

0 commit comments

Comments
 (0)