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

Refactor CSS style classes to have a "Inherit", "Initial", etc. base class #356

Open
bitspittle opened this issue Oct 18, 2023 · 0 comments
Labels
good first issue Good for newcomers process Something that needs to be done but may not be user visible
Milestone

Comments

@bitspittle
Copy link
Collaborator

This pattern is EVERYWHERE in our codebase:

class SomeCssStyle private constructor(private val value: String) : StylePropertyValue {
    override fun toString() = value

    companion object {
        // Keyword
        val Normal get() = SomeCssStyle("normal")
        val Whatever get() = SomeCssStyle("whatever")

        // Global
        val Inherit get() = SomeCssStyle("inherit")
        val Initial get() = SomeCssStyle("initial")
        val Revert get() = SomeCssStyle("revert")
        val Unset get() = SomeCssStyle("unset")
    }
}

We should probably run through and simplify it to something like:

abstract class <T: CssStyleProperty> CssStyleProperty protected constructor(private val value: String) {
        val Inherit get() = unsafeCast<T>("inherit")
        val Initial get() = unsafeCast<T>("initial")
        val Revert get() = unsafeCast<T>("revert")
        val Unset get() = unsafeCast<T>("unset")   
}

class SomeCssStyle private constructor(value: String) : CssStyleProperty<SomeCssStyle>(value) {
    companion object {
        // Keyword
        val Normal get() = SomeCssStyle("normal")
        val Whatever get() = SomeCssStyle("whatever")
    }
}
@bitspittle bitspittle added good first issue Good for newcomers process Something that needs to be done but may not be user visible labels Oct 18, 2023
@bitspittle bitspittle added this to the 1.0 milestone Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers process Something that needs to be done but may not be user visible
Projects
None yet
Development

No branches or pull requests

1 participant