question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Composition with custom colors doesn't work.

See original GitHub issue

Hi there, first of all, I am in love with this package.

There is weird issue i am facing with custom colors. I have created a react button:

import { apply, tw } from 'twind';
import React, { useMemo } from 'react';


const baseStyles = apply`min-w-44 inline-flex items-center justify-center transition-all rounded-lg outline-none cursor-pointer focus:outline-none px-10 py-2 text-sm font-medium leading-5`;

const buttonStylesMap = {
  primary: apply`text-white hover:bg-primary-600 hover:ring-4 ring-red-200 bg-primary-500`,
  secondary: apply`bg-primary-100 text-red-500`,
  tertiary: apply`text-gray-600 border hover:bg-gray-100`,
  ghost: apply`hover:bg-gray-100`,
}

const Button = ({ type, children, loading, className, ...rest }) => {
  /*
   * returns the children to be rendered
   *
   * @returns
   */
  const computedChildren = useMemo(() => {
    if (loading) {
      return <span className={tw`animate-spin`}>
        <Icon>
          <LoaderIcon />
        </Icon>
      </span>
    }

    return children;
  }, [loading, children]);

  const instanceStyles = apply`
    ${baseStyles}
    ${buttonStylesMap[type]}`;

  return (
    <button className={tw(instanceStyles, className)}
      {...rest}
    >
      {computedChildren}
    </button>
  );
};

export default Button;

and I am using custom twind.config.js:

const { apply } = require('twind');

/** @type {import('twind').Configuration} */
module.exports = {
  theme: {
    extend: {
      colors: {
        primary: {
          100: '#e6f5ff',
          200: '#ccebff',
          300: '#99d6ff',
          400: '#99d6ff',
          500: '#0099ff',
          600: '#008ae6',
          700: '#006bb3',
          800: '#008ae6',
        },
      },
    },
  },
};

The above snippet does not work but if i use any other color other than the custom color ( say bg-red-500 instead of bg-primary-500 ), its works perfectly then. Am i missing anything or is it a bug?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
jsartisancommented, Oct 9, 2021

Also, one thing I forgot to mention, I am doing all of this in nextjs app. and one weird behavior is everything starts working when I navigate from one page to another but does not work on the first render. Maybe it’s an issue with SSR?

0reactions
sastancommented, Dec 15, 2022

I have tested this with twind v1 and could not reproduce the issue. I used the https://github.com/tw-in-js/twind/tree/main/examples/with-next example and added your code to the index.jsx.

Please re-open if you still have this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Compose Custom Theme colors - Text color not ...
Android Compose Custom Theme colors - Text color not picking the theme color ... colorPrimary, // this doesn't work style ...
Read more >
Custom design systems in Compose - Android Developers
We recommend you access values you set from your custom theme. Alternatively, if your theme doesn't provide Color , TextStyle , Shape ,...
Read more >
Change compose message window background but not ...
I would like to change the compose message background color, I have the TT DeepDark theme so everything is black/grey, but leaving the ......
Read more >
Background color not showing - Adobe Support Community
The background color of a comp WILL NOT RENDER. ... When you first start out none of you compositions should say Custom in...
Read more >
How to create a truly custom theme in Jetpack Compose
The last step is to create the LocalColors object. It's an instance of CompositionLocal which does 2 things: implicitly passes color attributes ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found