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 styles don't seem to work. #17

Open
CoreyVincent opened this issue Mar 4, 2022 · 13 comments
Open

Class styles don't seem to work. #17

CoreyVincent opened this issue Mar 4, 2022 · 13 comments

Comments

@CoreyVincent
Copy link

CoreyVincent commented Mar 4, 2022

Styles don't seem to work. I've used the class attribute to add multiple classes. None of them show up.
I would prefer this to having to use the style attribute and write out all the styles.

Here's an example:

import { inject } from 'vue'
import { Toast } from 'vue-dk-toast'

const toast = inject<Toast>('$toast')

if (toast) toast('Gray', {
    duration: false,
    positionY: 'top',
    positionX: 'right',
    disableClick: false,
    class: ['bg-gray-200', 'rounded-sm']
})
if (toast) toast('Blue', {
    duration: false,
    positionY: 'top',
    positionX: 'right',
    disableClick: false,
    class: ['bg-blue-400', 'rounded-sm']
})

image

@Daniel-Knights
Copy link
Owner

Are you calling inject outside setup? It only works inside

@CoreyVincent
Copy link
Author

CoreyVincent commented Mar 4, 2022

I'm using <script setup lang='ts'>.

I just tried this with the same results.:

<script lang="ts">
import { Toast } from 'vue-dk-toast'
export default {
    setup() {

        const toast = inject<Toast>('$toast')
        if (toast) toast('Blue', {
            duration: false,
            positionY: 'top',
            positionX: 'right',
            disableClick: false,
            class: ['bg-blue-400', 'rounded-sm'],
            slotLeft: '<svg className="max-w-6 max-h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" /></svg>',
        })
        return {

        }
    }
}
</script>

@Daniel-Knights
Copy link
Owner

If you check dev-tools do the classes get applied to the element?

@CoreyVincent
Copy link
Author

They seem to:
image

And all my other styling are showing up correctly, just not on the toasts.

@Daniel-Knights
Copy link
Owner

Daniel-Knights commented Mar 4, 2022

Okay, think it might just be an issue with style specificity in that case. Could you check the styles to see if any of the dk__... classes are overriding the Tailwind classes?

I've made the classes as flat and low specificity as possible but would be good to know if it doesn't play nice with Tailwind

@CoreyVincent
Copy link
Author

That does perhaps look to be the case:
image

@Daniel-Knights
Copy link
Owner

Does Tailwind append a stylesheet to <head>?

Just wondering if you could get around this by initialising Tailwind before the toast, so the stylesheet appears first

@CoreyVincent
Copy link
Author

That's a good question.
It looks like Tailwind is being initialized before your toasts.
I'm using vite with tailwind, I have no idea how to control the import order though. I would imagine we would want the toast first, I think that's how css works(latter styling overwrites the earlier styling).

image
*Really hard to write letters with a mouse 😣

@Daniel-Knights
Copy link
Owner

Ah yeah, maybe import the Tailwind CSS file in App.vue? Should load it after the toast I think

@CoreyVincent
Copy link
Author

CoreyVincent commented Mar 4, 2022

Yup, that did it.

Moved the @tailwind imports into the <style> tag of App.vue.

Does not work if you keep the @tailwind imports in a main.css and import that in the <script> tag of App.vue.
Must be placed in the <style> tag.

Not sure if that's the best way of doing it, but I'll work with it for now.
@Daniel-Knights Thanks for your help.

@CoreyVincent
Copy link
Author

Any chance you can remove the styles that are non-essential? It would allow for a more bare-bones styling approach.

@Daniel-Knights
Copy link
Owner

Noice, no problem.

Changing base styles would be a breaking change at this point and I think it wouldn't serve much purpose in terms of usability. Maybe an extra option to remove them 🤔 I'll think on that one

@CoreyVincent
Copy link
Author

CoreyVincent commented Mar 4, 2022

I spoke too soon.
It appears to still be overriding the styles. I'm trying to figure out why, but it's randomly overriding the styles.

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

2 participants