Skip to content

refactor(frontend): own Toggle natively, detach from gix#13165

Open
AntonioVentilii wants to merge 24 commits into
mainfrom
av/gix-own-toggle
Open

refactor(frontend): own Toggle natively, detach from gix#13165
AntonioVentilii wants to merge 24 commits into
mainfrom
av/gix-own-toggle

Conversation

@AntonioVentilii

Copy link
Copy Markdown
Collaborator

Motivation

Bring the gix Toggle fully in-house as a native OISY component — the pilot for migrating every component we use off @dfinity/gix-components (so gix can go into maintenance mode). This PR shows the pattern the rest of the fleet will follow. Stacked on #13163.

Changes

  • New $lib/components/ui/Toggle.svelte, written natively in Svelte 5: runes + a typed onToggle(checked) callback prop, replacing the legacy createEventDispatcher/on:nnsToggle event.
  • Fold the adaptations in: the former gix.scss override layer for this component (div.toggle sizing/colors/responsive breakpoints, --toggle-disabled-opacity) now lives in the component's own <style>. We no longer hand-patch a third-party component from a global stylesheet.
  • Native test id (toggle instead of gix-cmp-toggle).
  • Rewire all 11 consumers to the local import; convert the 7 on:nnsToggle handlers to onToggle; update the affected test.

Tests

  • lint --max-warnings 0 clean; check clean (only the pre-existing unrelated sol-instructions-system error on main)
  • EnableTokenToggle, TokensCategoryFilterToggle (18), Settings, SettingsExperimentalFeatures (3) pass

Review focus (pattern decisions for the fleet)

  1. Native naming/placement: $lib/components/ui/Toggle.svelte.
  2. Svelte 4→5 conversion: onToggle callback vs keeping the legacy event — does this API feel right for OISY?
  3. Adaptation folding: gix.scss override → component style. Confirm this is how you want the hand-patches absorbed.

AntonioVentilii and others added 21 commits June 22, 2026 10:49
…util

First step of detaching OISY from @dfinity/gix-components: copy the
cross-cutting primitives that are used across configs/constants and many
unrelated wizards (owned by no single component) into OISY's own lib, and
rewire their imports off gix.

- types/wizard.ts (WizardStep, WizardSteps)
- types/progress-step.ts (ProgressStep, ProgressStepState)
- types/event-modifiers.ts + utils/event-modifiers.utils.ts (preventDefault, stopPropagation)

No new npm dependencies, no behavior change (types are erased; the two
utils are identical). gix dependency stays in place until all components
are migrated.
Second cross-cutting step of detaching from @dfinity/gix-components: bring
the iOS device-detection helper into OISY's own device.utils.

- add isNode() to env.utils (gix internal helper, needed by the guards)
- add userAgent/isIPad/isIOS to device.utils, reusing OISY's existing isMobile
- rewire the 9 isIOS consumers off gix

Stateful gix singletons (theme.store, toasts.store) are intentionally NOT
moved here: they must migrate atomically with their components and all
readers/writers, so they belong to their respective component PRs.
…nteraction/overlay)

Shared-style gate for detaching from @dfinity/gix-components. These 5 mixins
have no OISY equivalent and are used by multiple gix components being brought
in-house; vendoring them once here keeps the upcoming per-component PRs from
each re-adding the same files. OISY's existing _media/_text/_button mixins are
API-compatible with gix's, so those are reused as-is.

Stacked on #13162. Partials are unused until the component PRs @use them.
First component brought fully in-house from @dfinity/gix-components as a
native OISY component (pilot for the rest of the migration).

- New $lib/components/ui/Toggle.svelte, converted to Svelte 5 (runes + a
  typed onToggle callback prop instead of the legacy createEventDispatcher
  'nnsToggle' event)
- Fold the former gix.scss override layer (div.toggle sizing/colors/breakpoints
  and --toggle-disabled-opacity) directly into the component's own styles, so
  we no longer hand-patch a third-party component from afar
- Native test id ('toggle' instead of 'gix-cmp-toggle')
- Rewire all 11 consumers + update the 7 event handlers and the affected test

Stacked on #13163.
Address review: preventDefault/stopPropagation no longer force an async
boundary. The modifier call already ran synchronously before the await, but
the async wrapper turned synchronous callback throws into floating rejections.
Now we call and return the callback result, preserving synchronous error
semantics while still supporting async callbacks (their promise is returned).
Address review: add unit tests for the device-detection helpers introduced
when detaching isIOS from gix. isIPad/isIOS guard on isNode() (true in the
Node test runtime), so env.utils.isNode is mocked to false to exercise the
UA branching (iOS 12 iPad, iPadOS 13+ Macintosh+mobile, desktop Mac, iPhone/
iPod, non-iOS). Also cover isNode itself (present vs absent process).
Address review on the vendored mixin partials:
- Remove the unused h1-h5 heading mixins from _fonts (no vendored component
  uses them; they referenced undefined --line-height-h* vars).
- Add fallbacks for the CSS variables the still-used mixins reference but that
  OISY doesn't yet define globally (only via the gix override layer):
  --font-size-standard, --input-background-contrast, --focus-background-contrast,
  --toast-inverted-background(-contrast). Fallbacks use OISY's own tokens so the
  mixins emit valid CSS; the consuming component PRs will finalise the wiring.
Reverse course on vendoring gix's styling mixins wholesale. _form/_overlay/
_fonts encoded gix's CSS-variable contract (vars OISY doesn't own), which is
not native. Drop them from the shared gate; the Input/Checkbox/Modal/Toast PRs
will reproduce that styling natively with OISY design tokens.

Keep only the self-contained, token-free helpers actually shared across
component bundles: display.inset and interaction.{tappable,initial,none}.
OISY's existing _media/_text/_button mixins continue to be reused as-is.
Base automatically changed from av/gix-vendor-shared-mixins to main June 22, 2026 20:06
@AntonioVentilii AntonioVentilii marked this pull request as ready for review June 22, 2026 20:07
@AntonioVentilii AntonioVentilii requested a review from a team as a code owner June 22, 2026 20:07
Copilot AI review requested due to automatic review settings June 22, 2026 20:07
@zeropath-ai

zeropath-ai Bot commented Jun 22, 2026

Copy link
Copy Markdown

No security or compliance issues detected. Reviewed everything up to ed76cc8.

Security Overview
Detected Code Changes
Change Type Relevant files
Refactor ► src/frontend/src/btc/components/tokens/BtcManageTokenToggle.svelte
    Replace @dfinity/gix-components Toggle with local Toggle component
► src/frontend/src/icp/components/tokens/IcManageTokenToggle.svelte
    Replace @dfinity/gix-components Toggle with local Toggle component
► src/frontend/src/lib/components/networks/ManageNetworkToggle.svelte
    Replace @dfinity/gix-components Toggle with local Toggle component
► src/frontend/src/lib/components/nfts/NftsShowHiddenToggle.svelte
    Replace @dfinity/gix-components Toggle with local Toggle component
► src/frontend/src/lib/components/nfts/NftsShowSpamToggle.svelte
    Replace @dfinity/gix-components Toggle with local Toggle component
► src/frontend/src/lib/components/settings/Settings.svelte
    Replace @dfinity/gix-components Toggle with local Toggle component
► src/frontend/src/lib/components/settings/SettingsExperimentalFeatures.svelte
    Replace @dfinity/gix-components Toggle with local Toggle component
► src/frontend/src/lib/components/tokens/ManageTokenToggle.svelte
    Replace @dfinity/gix-components Toggle with local Toggle component
► src/frontend/src/lib/components/tokens/TokensCategoryFilterToggle.svelte
    Replace @dfinity/gix-components Toggle with local Toggle component
► src/frontend/src/lib/components/tokens/TokensZeroBalanceToggle.svelte
    Replace @dfinity/gix-components Toggle with local Toggle component
► src/frontend/src/lib/components/ui/Toggle.svelte
    Create a new local Toggle component
► src/frontend/src/lib/styles/global/gix.scss
    Remove global styles for Toggle component
► src/frontend/src/sol/components/tokens/SolManageTokenToggle.svelte
    Replace @dfinity/gix-components Toggle with local Toggle component
► src/frontend/src/tests/lib/components/tokens/EnableTokenToggle.spec.ts
    Update test to reference new Toggle component testId
Enhancement ► src/frontend/src/icp/components/tokens/IcManageTokenToggle.svelte
    Update Toggle event handler from on:nnsToggle to onToggle
► src/frontend/src/lib/components/networks/ManageNetworkToggle.svelte
    Update Toggle event handler from on:nnsToggle to onToggle
► src/frontend/src/lib/components/settings/Settings.svelte
    Update Toggle event handler from on:nnsToggle to onToggle
► src/frontend/src/lib/components/settings/SettingsExperimentalFeatures.svelte
    Update Toggle event handler from on:nnsToggle to onToggle
► src/frontend/src/lib/components/tokens/ManageTokenToggle.svelte
    Update Toggle event handler from on:nnsToggle to onToggle
► src/frontend/src/lib/components/tokens/TokensCategoryFilterToggle.svelte
    Update Toggle event handler from on:nnsToggle to onToggle
► src/frontend/src/lib/components/tokens/TokensZeroBalanceToggle.svelte
    Update Toggle event handler from on:nnsToggle to onToggle

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the Toggle UI primitive off @dfinity/gix-components into a native Svelte 5 $lib/components/ui/Toggle.svelte, and rewires existing consumers/tests to use the in-house component and API.

Changes:

  • Added a native Toggle.svelte component (Svelte 5 runes) and moved prior gix override styling into the component.
  • Updated multiple toggle consumers to import the local Toggle and switch from on:nnsToggle to an onToggle(checked) callback prop.
  • Updated test selectors and removed the Toggle-specific global overrides from gix.scss.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/frontend/src/lib/components/ui/Toggle.svelte New native Toggle component + folded-in styling from prior global overrides.
src/frontend/src/lib/styles/global/gix.scss Removes Toggle-specific global overrides (now owned by the native component).
src/frontend/src/lib/components/tokens/ManageTokenToggle.svelte Switches to local Toggle and migrates event wiring to onToggle.
src/frontend/src/icp/components/tokens/IcManageTokenToggle.svelte Switches to local Toggle and migrates event wiring to onToggle.
src/frontend/src/lib/components/tokens/TokensZeroBalanceToggle.svelte Switches to local Toggle and migrates event wiring to onToggle.
src/frontend/src/lib/components/tokens/TokensCategoryFilterToggle.svelte Switches to local Toggle and migrates event wiring to onToggle.
src/frontend/src/lib/components/settings/Settings.svelte Switches settings toggle to local Toggle and onToggle.
src/frontend/src/lib/components/settings/SettingsExperimentalFeatures.svelte Switches feature toggles to local Toggle and onToggle.
src/frontend/src/lib/components/networks/ManageNetworkToggle.svelte Switches to local Toggle and passes onToggle through.
src/frontend/src/lib/components/nfts/NftsShowSpamToggle.svelte Switches to local Toggle import.
src/frontend/src/lib/components/nfts/NftsShowHiddenToggle.svelte Switches to local Toggle import.
src/frontend/src/btc/components/tokens/BtcManageTokenToggle.svelte Switches to local Toggle import.
src/frontend/src/sol/components/tokens/SolManageTokenToggle.svelte Switches to local Toggle import.
src/frontend/src/tests/lib/components/tokens/EnableTokenToggle.spec.ts Updates test id from gix-cmp-toggle to toggle.

Comment thread src/frontend/src/lib/components/ui/Toggle.svelte
Comment thread src/frontend/src/lib/components/tokens/ManageTokenToggle.svelte
Comment thread src/frontend/src/icp/components/tokens/IcManageTokenToggle.svelte
Two fixes on the native Toggle:
- The input used bind:checked (two-way) while consumers' handlers still flip
  checked themselves (checked = !checked) — a double-toggle. Revert to gix's
  one-way model (checked={checked} + onToggle(newValue)); consumers' existing
  handlers do the flip exactly as before. Restores behavioral parity.
- The folded responsive overrides used theme(--breakpoint-*), which Tailwind
  only resolves in global styles, not in a component's scoped <style> (broke
  vite/lightningcss build). Inline the literal Tailwind values (1024px / 640px).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants