From 943795f5ca75f543cb0b201dc05ba27ba9ecae81 Mon Sep 17 00:00:00 2001 From: Hunter Perrin Date: Mon, 15 Nov 2021 14:22:26 -0800 Subject: [PATCH] feat: migrate switch to new mdc-web version --- MIGRATING.md | 10 +- packages/ripple/Ripple.ts | 7 +- ...aryColor.svelte => _SecondaryColor.svelte} | 4 +- .../site/src/routes/demo/switch/index.svelte | 6 +- packages/switch/Switch.svelte | 218 +++++++++--------- packages/switch/Switch.types.ts | 23 +- packages/switch/_mixins.scss | 50 ++-- packages/switch/package.json | 3 +- 8 files changed, 176 insertions(+), 145 deletions(-) rename packages/site/src/routes/demo/switch/{_PrimaryColor.svelte => _SecondaryColor.svelte} (80%) diff --git a/MIGRATING.md b/MIGRATING.md index f56153e63..60db7f05a 100644 --- a/MIGRATING.md +++ b/MIGRATING.md @@ -7,6 +7,14 @@ This doc contains information that will help you migrate your code from an older SMUI 6 migrated to upstream MDC 13.0 from 11.0: https://github.com/material-components/material-components-web/blob/master/CHANGELOG.md#1300-2021-09-24 +## Changes + +### Components + +- Switch + - No longer needs `valueKey` prop. + - Default color is now "primary". + # SMUI 4 -> SMUI 5 ## Breaking Changes @@ -45,7 +53,7 @@ You should update your MDC dependencies to 11.0 as well. ## New Features -### Compoennts +### Components - Banner - Add focus trap on the banner. diff --git a/packages/ripple/Ripple.ts b/packages/ripple/Ripple.ts index e79f593d3..cb228b8ec 100644 --- a/packages/ripple/Ripple.ts +++ b/packages/ripple/Ripple.ts @@ -13,6 +13,7 @@ export type RippleProps = { color?: 'primary' | 'secondary'; /** Whether the ripple is active. Leave null to determine automatically. */ active?: boolean; + rippleElement?: HTMLElement; eventTarget?: HTMLElement; activeTarget?: HTMLElement; addClass?: (className: string) => void; @@ -30,6 +31,7 @@ export default function Ripple( disabled = false, color, active, + rippleElement, eventTarget, activeTarget, addClass = (className) => node.classList.add(className), @@ -77,7 +79,8 @@ export default function Ripple( instance = new MDCRippleFoundation({ addClass, browserSupportsCssVars: () => util.supportsCssVariables(window), - computeBoundingRect: () => node.getBoundingClientRect(), + computeBoundingRect: () => + (rippleElement || node).getBoundingClientRect(), containsEventTarget: (target) => node.contains(target as Node), deregisterDocumentInteractionHandler: (evtType, handler) => document.documentElement.removeEventListener( @@ -177,6 +180,7 @@ export default function Ripple( disabled, color, active, + rippleElement, eventTarget, activeTarget, addClass, @@ -190,6 +194,7 @@ export default function Ripple( disabled: false, color: undefined, active: undefined, + rippleElement: undefined, eventTarget: undefined, activeTarget: undefined, addClass: (className) => node.classList.add(className), diff --git a/packages/site/src/routes/demo/switch/_PrimaryColor.svelte b/packages/site/src/routes/demo/switch/_SecondaryColor.svelte similarity index 80% rename from packages/site/src/routes/demo/switch/_PrimaryColor.svelte rename to packages/site/src/routes/demo/switch/_SecondaryColor.svelte index 379b5e7b8..a1ff3faba 100644 --- a/packages/site/src/routes/demo/switch/_PrimaryColor.svelte +++ b/packages/site/src/routes/demo/switch/_SecondaryColor.svelte @@ -1,6 +1,6 @@
- + Fields of grain.
@@ -9,7 +9,7 @@
- + Fields of grain.
diff --git a/packages/site/src/routes/demo/switch/index.svelte b/packages/site/src/routes/demo/switch/index.svelte index 06ec24bd9..ccb0df561 100644 --- a/packages/site/src/routes/demo/switch/index.svelte +++ b/packages/site/src/routes/demo/switch/index.svelte @@ -9,8 +9,8 @@ - - Primary color + + Secondary color Group switch @@ -20,6 +20,6 @@ import Demo from '$lib/Demo.svelte'; import Simple from './_Simple.svelte'; - import PrimaryColor from './_PrimaryColor.svelte'; + import SecondaryColor from './_SecondaryColor.svelte'; import Group from './_Group.svelte'; diff --git a/packages/switch/Switch.svelte b/packages/switch/Switch.svelte index c71487539..6e8b56c30 100644 --- a/packages/switch/Switch.svelte +++ b/packages/switch/Switch.svelte @@ -1,59 +1,69 @@ -
instance && instance.handleClick()} + {...inputProps} + {...exclude($$restProps, ['icons$'])} >
-
-
- +
+
+
+
+
+
+
+ + + + + + +
+
-
+