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

Feature/twmerge as composable #250

Merged
merged 4 commits into from
Dec 5, 2023

Conversation

Sqrcz
Copy link
Collaborator

@Sqrcz Sqrcz commented Nov 15, 2023

This is a way to move twMerge as global composable instead of importing it each component.

Also this is a way to solve issue with custom user classes... proof of concept working for button, and main container of navbar.

@Sqrcz Sqrcz marked this pull request as ready for review November 15, 2023 12:31
@cogor
Copy link
Collaborator

cogor commented Nov 22, 2023

Great suggestion, but if I'll add my custom class to button my classes will duplicated, to fix that you need to disable inheritAttrs and bind $attrs on root(or not) element

<template>
  <component
    v-bind="$attrs"
    :is="buttonComponent"
    :class="wrapperClasses"
    :[linkAttr]="href"
    :disabled="buttonComponent === 'button' && disabled"
  >
    ...
  </component>
</template>
<script lang="ts" setup>
/// ...

defineOptions({
  inheritAttrs: false,
})
/// ...

@Sqrcz
Copy link
Collaborator Author

Sqrcz commented Nov 23, 2023

Thanks, I'll take a look at this and prepare a fix.

Copy link

netlify bot commented Dec 5, 2023

Deploy Preview for sensational-seahorse-8635f8 ready!

Name Link
🔨 Latest commit 6198cdf
🔍 Latest deploy log https://app.netlify.com/sites/sensational-seahorse-8635f8/deploys/656f286603559e0008edaa53
😎 Deploy Preview https://deploy-preview-250--sensational-seahorse-8635f8.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Sqrcz
Copy link
Collaborator Author

Sqrcz commented Dec 5, 2023

Hey @cogor 👋

I've tested different options here... and adding v-bind="$attrs" would require a way to filter unwanted parts which is not ideal when done manually... but we can take advantage of Vue's Attribute Inheritance. Especially this part: not explicitly declared in the receiving component's props or emits.

I've updated this PR with necessary changes... and I'm not getting duplicated classes and I'm able to add basic styles using regular class attribute.

Let me know what do you think about this approach.

@cogor
Copy link
Collaborator

cogor commented Dec 5, 2023

Looks great

@cogor cogor merged commit 32d9c4a into themesberg:main Dec 5, 2023
11 checks passed
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