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

class name functions #257

Merged
merged 4 commits into from
Feb 24, 2021
Merged

class name functions #257

merged 4 commits into from
Feb 24, 2021

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Feb 23, 2021

Every component that accepts a className should be able to pass in a
function. This function will retrieve the render prop arg for this
component. The function should resolve to a string in the end.

This makes the API a bit nicer if you just need to change the classNames
based on some internal state.

E.g.:

// Before
<Menu.Button as={Fragment}>
  {({ open }) => (
    <button className={open ? 'font-bold' : 'font-normal'}>
      Hello
    </button>
  )}
</Menu.Button>

// After
<Menu.Button className={({ open }) => open ? 'font-bold' : 'font-normal'}>
  Hello
</Menu.Button>

Every component that accepts a className should be able to pass in a
function. This function will retrieve the render prop arg for this
component. The function should resolve to a string in the end.

This makes the API a bit nicer if you just need to change the classNames
based on some internal state.

E.g.:

```js
// Before
<Menu.Button as={Fragment}>
  {({ open }) => (
    <button className={open ? 'font-bold' : 'font-normal'}>
      Hello
    </button>
  )}
</Menu.Button>

// After
<Menu.Button className={({ open }) => open ? 'font-bold' : 'font-normal'}>
  Hello
</Menu.Button>
```
@vercel
Copy link

vercel bot commented Feb 23, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

headlessui-react – ./packages/@headlessui-react

🔍 Inspect: https://vercel.com/tailwindlabs/headlessui-react/9smLTh7YjjqvAFzT31Kdfw1UAx4j
✅ Preview: https://headlessui-react-git-class-name-functions-tailwindlabs.vercel.app

headlessui-vue – ./packages/@headlessui-vue

🔍 Inspect: https://vercel.com/tailwindlabs/headlessui-vue/5yEun6TrZFB9uE8oRZZf1mtNnZtB
✅ Preview: https://headlessui-vue-git-class-name-functions-tailwindlabs.vercel.app

@RobinMalfait RobinMalfait merged commit 01508f0 into develop Feb 24, 2021
@RobinMalfait RobinMalfait deleted the class-name-functions branch February 24, 2021 00:12
This was referenced Mar 15, 2021
RobinMalfait added a commit that referenced this pull request Mar 22, 2021
* allow className to be a function

Every component that accepts a className should be able to pass in a
function. This function will retrieve the render prop arg for this
component. The function should resolve to a string in the end.

This makes the API a bit nicer if you just need to change the classNames
based on some internal state.

E.g.:

```js
// Before
<Menu.Button as={Fragment}>
  {({ open }) => (
    <button className={open ? 'font-bold' : 'font-normal'}>
      Hello
    </button>
  )}
</Menu.Button>

// After
<Menu.Button className={({ open }) => open ? 'font-bold' : 'font-normal'}>
  Hello
</Menu.Button>
```

* cleanup types

* merge React imports

* update changelog
RobinMalfait added a commit that referenced this pull request Mar 26, 2021
* allow className to be a function

Every component that accepts a className should be able to pass in a
function. This function will retrieve the render prop arg for this
component. The function should resolve to a string in the end.

This makes the API a bit nicer if you just need to change the classNames
based on some internal state.

E.g.:

```js
// Before
<Menu.Button as={Fragment}>
  {({ open }) => (
    <button className={open ? 'font-bold' : 'font-normal'}>
      Hello
    </button>
  )}
</Menu.Button>

// After
<Menu.Button className={({ open }) => open ? 'font-bold' : 'font-normal'}>
  Hello
</Menu.Button>
```

* cleanup types

* merge React imports

* update changelog
RobinMalfait added a commit that referenced this pull request Apr 2, 2021
* allow className to be a function

Every component that accepts a className should be able to pass in a
function. This function will retrieve the render prop arg for this
component. The function should resolve to a string in the end.

This makes the API a bit nicer if you just need to change the classNames
based on some internal state.

E.g.:

```js
// Before
<Menu.Button as={Fragment}>
  {({ open }) => (
    <button className={open ? 'font-bold' : 'font-normal'}>
      Hello
    </button>
  )}
</Menu.Button>

// After
<Menu.Button className={({ open }) => open ? 'font-bold' : 'font-normal'}>
  Hello
</Menu.Button>
```

* cleanup types

* merge React imports

* update changelog
RobinMalfait added a commit that referenced this pull request Apr 2, 2021
* allow className to be a function

Every component that accepts a className should be able to pass in a
function. This function will retrieve the render prop arg for this
component. The function should resolve to a string in the end.

This makes the API a bit nicer if you just need to change the classNames
based on some internal state.

E.g.:

```js
// Before
<Menu.Button as={Fragment}>
  {({ open }) => (
    <button className={open ? 'font-bold' : 'font-normal'}>
      Hello
    </button>
  )}
</Menu.Button>

// After
<Menu.Button className={({ open }) => open ? 'font-bold' : 'font-normal'}>
  Hello
</Menu.Button>
```

* cleanup types

* merge React imports

* update changelog
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.

1 participant