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

Add tiny abstraction over elements where low-level control doesn't make sense #24

Closed
Dzoukr opened this issue Apr 9, 2020 · 8 comments
Labels

Comments

@Dzoukr
Copy link
Owner

Dzoukr commented Apr 9, 2020

As agreed on #20, for some chosen elements like tabs we should create tiny layer of abstraction to make work with it easier.

@Dzoukr Dzoukr added the version2 label Apr 9, 2020
@Dzoukr Dzoukr mentioned this issue Apr 9, 2020
5 tasks
@MangelMaxime
Copy link
Contributor

The element pagination-ellipsis is also a god candidate for this.

Here is how it is implemented in Fulma:

    /// Generate <li><button class="pagination-ellipsis">&hellip;</button></li>
    /// You control the `button` element
    let ellipsis (options: GenericOption list) =
        li [ ]
           [ GenericOptions
                .Parse(options, parseOptions, "pagination-ellipsis")
                .AddProp(DangerouslySetInnerHTML { __html = "&hellip;" })
                .ToReactElement(span) ]

@MangelMaxime
Copy link
Contributor

When working on #21, I am also adding some tiny abstraction over some of the elements. Only tiny ones when reading the PR we will be to review if all of them make sense of not.

Right now, I am porting everything from Fulma as most of them has been asked by the community over time.

@MangelMaxime
Copy link
Contributor

In Fulma, tabs abstraction is really simple:

    /// Generate <div class="tabs"><ul></ul></div>
    let tabs (options: Option list) children =
        let parseOptions (result : GenericOptions) option =
            match option with
            | IsCentered
            | IsRight
            | IsBoxed
            | IsToggle
            | IsToggleRounded
            | IsFullWidth -> result.AddCaseName option
            | Size size -> ofSize size |> result.AddClass
            | Props props -> result.AddProps props
            | CustomClass customClass -> result.AddClass customClass
            | Modifiers modifiers -> result.AddModifiers modifiers

        GenericOptions.Parse(options, parseOptions, "tabs").ToReactElement(div, [ ul [ ] children ])

    /// Generate <li></li>
    let tab (options: Tab.Option list) children =
        let parseOptions (result : GenericOptions) option =
            match option with
            | Tab.IsActive state -> if state then result.AddCaseName option else result
            | Tab.Props props -> result.AddProps props
            | Tab.CustomClass customClass -> result.AddClass customClass
            | Tab.Modifiers modifiers -> result.AddModifiers modifiers

        GenericOptions.Parse(options, parseOptions).ToReactElement(li, children)

The idea, is that whenever the user use Tabs.tabs we directly add the ul under the div because we know it is required.

@MangelMaxime
Copy link
Contributor

The button element can also be a candidate:

    module Input =
        let internal btnInput typ options =
            let hasProps =
                options
                |> List.exists (fun opts ->
                    match opts with
                    | Props _ -> true
                    | _ -> false
                )

            if hasProps then
                let newOptions =
                    options
                    |> List.map (fun opts ->
                        match opts with
                        | Props props -> Props ((Type typ :> IHTMLProp) ::props)
                        | forward -> forward
                    )
                btnView (fun options _ -> input options) newOptions [ ]

            else
                btnView (fun options _ -> input options) ((Props [ Type typ ])::options) [ ]

        /// Generate <input type="reset" class="button" />
        let reset options = btnInput "reset" options
        /// Generate <input type="submit" class="button" />
        let submit options = btnInput "submit" options

The idea is it add the correct type directly, yep I am lazy sometimes ^^

@MangelMaxime
Copy link
Contributor

In fact, you already added the button reset and submit specialization

MangelMaxime added a commit to MangelMaxime/Feliz.Bulma that referenced this issue Apr 14, 2020
@Dzoukr
Copy link
Owner Author

Dzoukr commented Apr 15, 2020

I think we can mark this one as done as well, can't we?

@MangelMaxime
Copy link
Contributor

There is still the tabs/tab abstraction to make I think. I didn't check the source code beforing saying that so can be wrong

MangelMaxime added a commit to MangelMaxime/Feliz.Bulma that referenced this issue Apr 20, 2020
@Dzoukr
Copy link
Owner Author

Dzoukr commented Apr 21, 2020

Ok, I assume this one is now (thanks to Maxime) done

@Dzoukr Dzoukr closed this as completed Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants