Code Monkey home page Code Monkey logo

Comments (6)

macandcheese avatar macandcheese commented on June 5, 2024 1

I like @patrickarlt's idea of a custom decorator.. I think the vast majority of "simple" prop validations will just be along the lines of...

  @Prop({ reflect: true }) color: string = 'blue';
  @Prop({ reflect: true }) theme: string = null;

  ...

  componentWillLoad() {  
    let colors = ['blue', 'red', 'green', 'yellow']
    if (!colors.includes(this.color)) this.color = 'blue';

    let themes = ['dark', 'light']
    if (this.theme !== null && !themes.includes(this.theme)) this.theme = 'light';
}

so to me an ideal solution that could cover most "initial load validations" would be ...

@ValidateProp({ reflect: true }) color: 'blue' | 'red' | 'yellow' | 'green' = 'blue';
@ValidateProp({ reflect: true }) theme: 'dark' | 'light' = null;

and then you could use the existing "@ Watch" for anything more complex or "on change" validations

from calcite-design-system.

macandcheese avatar macandcheese commented on June 5, 2024

Slots would be super tough to validate in any consistent manner IMO... But props should be, within reason.

For instance, validating that color is one of "red, green, blue, yellow" or theme is one of "dark, light" seems doable.

from calcite-design-system.

kumarGayu avatar kumarGayu commented on June 5, 2024

One possible way I can think of validating this.el.children and validate how many and which element it is. But I am not sure how much trustworthy or how efficient it is.

from calcite-design-system.

julio8a avatar julio8a commented on June 5, 2024

What's the status of this issue? can we close this one?

from calcite-design-system.

julio8a avatar julio8a commented on June 5, 2024

Checking back in on this one.

from calcite-design-system.

macandcheese avatar macandcheese commented on June 5, 2024

Closing this due to inactivity, feel free to open another if something specific is needed.

from calcite-design-system.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.