Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I change customize dynamically, and why doesn't the component update with ticks? #264

Open
Lippiece opened this issue Sep 30, 2024 · 0 comments

Comments

@Lippiece
Copy link

Lippiece commented Sep 30, 2024

How do I change the fill and stroke during the lifecycle?

  • agree only works when not touching the display property and using svg mode.
  • agree2 doesn't work, with or without svg mode.
<script setup lang="ts">
const agree  = ref(false)
const agree2 = ref(false)

const setChecked   = (content: string) =>
  content
    .replaceAll(/stroke="[^"]*"/g, 'stroke="black"')
    .replaceAll(/fill="[^"]*"/g, 'fill="white"')
const setUnchecked = (content: string) =>
  content
    .replaceAll(/stroke="[^"]*"/g, 'stroke="black"')
    .replaceAll(/fill="[^"]*"/g, 'fill="yellow"')

const customize = (a, b) => (content: string) =>
  content.replaceAll(/stroke="[^"]*"/g, `stroke="${a}"`).replaceAll(/fill="[^"]*"/g, `fill="${b}"`)
</script>
<template>
  <label>
    <input
      v-model="agree"
      required
      type="checkbox"
      class="invisible absolute -z-10"
    >
    <Icon
      mode="svg"
      :customize="setChecked"
      name="local:checkbox"
      :class="{ hidden: !agree }"
    />
    <Icon
      :class="{ hidden: agree }"
      mode="svg"
      :customize="setUnchecked"
      name="local:checkbox"
    />
    Yes
  </label>
  <label>
    <input
      v-model="agree2"
      required
      type="checkbox"
      class="invisible absolute -z-10"
    >
    <Icon
      mode="svg"
      :customize="customize('black', 'white')"
      name="local:checkbox"
      :class="{ hidden: !agree }"
    />
    <Icon
      :class="{ hidden: agree }"
      mode="svg"
      :customize="customize('black', 'yellow')"
      name="local:checkbox"
    />
    Yes
  </label>
</template>
SVG

<svg width="20" height="20" viewBox="0 0 20 20" fill="none">
  <rect x="0.5" y="0.5" width="19" height="19" rx="3.5" fill="#24A3B6"/>
  <rect x="0.5" y="0.5" width="19" height="19" rx="3.5" stroke="#24A3B6"/>
  <g clip-path="url(#clip0_4188_74097)">
    <path d="M6 9.5L9.125 12.625L15.375 6.375" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
    </g>
  <defs>
    <clipPath id="clip0_4188_74097">
      <rect width="15" height="15" fill="white" transform="translate(3 2)"/>
      </clipPath>
    </defs>
  </svg>

`app.config.ts`

// app.config.ts
export default defineAppConfig({
  icon: {
    size             : '20px',
    customCollections: [
      {
        prefix: 'local',
        dir   : './assets/images/icons/'
      }
    ],
})

The number of times I've restarted Nuxt for debugging this is horrendous.

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

No branches or pull requests

1 participant