Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
Passing a string as a prop and using it to make a class name in Svelte

I have this BigButton component where I want to pass a bgColor prop :

<BigButton
        title="Join a Game"
        description="Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos, est?"
        icon="star"
        bgColor="blue-500"
    />

then on the component I handle it in the onMount hook:

<script lang="ts">
    import { onMount } from 'svelte';

    export let title: string;
    export let description: string = '';
    export let icon: string;
    export let bgColor: string | undefined;
    let iconUrl: string;

    onMount(() => {
        if (icon) iconUrl = `/icons/${icon}@2x.png`;
        if (bgColor) bgColor = `bg-${bgColor}`;
    });
</script>

<div
    class="flex flex-row w-96 rounded-3xl p-6 
    justify-center place-items-center {bgColor ? bgColor : 'bg-slate-400'}"
>

the component renders with the class name but the style is not applied.

I did something similar with the icon prop, which does work:

<img src={iconUrl} alt="gold star" />
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are using Tailwind, this relies heavily on post-processing of the code. My guess would be that if you do not include the full class name, the corresponding CSS will not be included in the output, because including every possible Tailwind class would create a massive file.

If you know what classes will be possible, you can also try to force the inclusion of those styles.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!