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

Form Components #62

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open

Form Components #62

wants to merge 31 commits into from

Conversation

richmarisa
Copy link
Contributor

Livewire Form Component library

This PR does the following

  • replicates the set of form elements in Tone's CSS Framework Form example page for use with Livewire 3, generating same/equivalent markup
  • attempts to create a simple, uncluttered UX for calling the components

To Review:

  • Read/review COMPONENTS.md
  • Read the component library implementation
  • (Extra credit:) use the Laravel Starter kit in a project to create a form and try a couple of these out.

Copy link
Collaborator

@woodseowl woodseowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great addition, Rich!

I have a couple ideas for consideration (see below). Also, I think it would be good to add a link to COMPONENTS.md in the main README.md next to the Libraries section and similarly brief.

I still need to do testing, but I don't expect to get to that right away, so just commenting on this for now.

COMPONENTS.md Outdated Show resolved Hide resolved
COMPONENTS.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@woodseowl woodseowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rich, I found a few issues while making a demo page with the form components (I still need to review dialogs). I've commented on items that were blockers to what appeared to be needed or intended functionality.

These came up as I built this form: https://laravel-demo-test.hosting.cornell.edu/forms (it's a deploy of laravel-demo components branch).

  • At the top of the page is what you had in the documentation.
  • That is followed by blocks that have the CSS Framework reference I was trying to reproduce and the Starter Kit components implementation as best I understood from the docs + code.

I'd be interested in talking about how close to get to the CSS Framework code, since some differences may be by design and I'm just not aware.

resources/views/components/cd/form/text.blade.php Outdated Show resolved Hide resolved
resources/views/components/cd/form/checkbox.blade.php Outdated Show resolved Hide resolved
resources/views/components/cd/form/checkboxes.blade.php Outdated Show resolved Hide resolved
resources/views/components/cd/form/checkbox.blade.php Outdated Show resolved Hide resolved
resources/views/components/cd/form/form-item.blade.php Outdated Show resolved Hide resolved
resources/views/components/cd/form/checkboxes.blade.php Outdated Show resolved Hide resolved
resources/views/components/cd/form/checkbox.blade.php Outdated Show resolved Hide resolved
resources/views/components/cd/form/radios.blade.php Outdated Show resolved Hide resolved
Copy link
Collaborator

@woodseowl woodseowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress! I updated the components on my test site and tried them out. There were a few more issues, but most of them are pretty quick fixes. At this point I have tested text field variations, checkbox variations, and selects. Radios, buttons, and dialogs still to go.

resources/views/components/cd/form/checkbox.blade.php Outdated Show resolved Hide resolved
aria-describedby="{{ $field }}_desc"
@endif
/>
<span class="option-label" for="{{$field}}">{!!$text??''!!}</span>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<span class="option-label" for="{{$field}}">{!!$text??''!!}</span>
<span class="option-label">{!! $text ?? $slot !!}</span>

Two suggestions here:

  • Remove the "for", because this is not a <label> tag and the attribute has no meaning
  • Supplement $text with $slot. I think in this layout this content is probably required, so taking advantage of the slot style seems like a nice implementation to me. But it's just an idea.

Regardless of whether you want to use text or slot, it needs to be documented in the README example, because I only found it when I couldn't figure out why my checkbox didn't show anything.

resources/views/components/cd/form/checkboxes.blade.php Outdated Show resolved Hide resolved
resources/views/components/cd/form/form-item.blade.php Outdated Show resolved Hide resolved
Comment on lines +1 to +5
<x-cd.form.form-item field="{{ $name ?? $attributes->whereStartsWith('wire:model')->first() }}"
classes="{{ $classes ?? '' }}"
required="{{ (($required??'') === 'false') ? 0 : (boolval($required??'')?1:0) }}"
:description="$description ?? ''"
>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this usage of form-item for the checkboxes is creating more problems than it is solving, but I don't see a simple solution. Here are the issues when I try to create a list of checkboxes like the CSSF example:

  • It nests the checkboxes as form-items inside a single form item
  • It adds a label, but there is no element with the id it says it's for
  • If a description is provided, it's placed after the list, which seems unlikely as a typical design pattern

I think the CSSF example would suggest just removing this wrapper entirely. But we lose the "required" feature and the automatic wiring for the description. It's easy enough to pull the description code up to this component. Not sure what to do for labeling and requiredness, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think other changes fix the form-items nesting; the trailing description is for consistency with other components. If you don't specify it, it doesn't appear. To fix the label issue, I think we need a div with the same styling as the label; I'll work on that.

resources/views/components/cd/form/select.blade.php Outdated Show resolved Hide resolved
resources/views/components/cd/form/README.md Show resolved Hide resolved
resources/views/components/cd/form/README.md Outdated Show resolved Hide resolved
resources/views/components/cd/form/cancelbutton.blade.php Outdated Show resolved Hide resolved
Comment on lines +2 to +5
<fieldset class="{{$legendtype??'default'}}"> {{-- default or semantic --}}
<legend @if ($legend_sr_only??false == 'true') class="sr-only" @endif >{{$legend??'Form'}}</legend>
{{$slot}}
</fieldset>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a fieldset part of the base form? It seems like the features of the fieldset here might be better abstracted to their own component and then if you need a fieldset you can use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is a WA consideration that is discussed in on Tone's form example page.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I've seen what you mention. That's a good reason for fieldset to be in a component. But I found that when I went to try to use a fieldset within <x-cd.form> that it was treated as a nested fieldset and I couldn't avoid it.

I'm not sure where the balance on this lies between ease of use of the x-cd.form component versus needing to implement work-arounds when it isn't doing what you need.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is optional.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a specific reference describing that a fieldset for a entire form is required? It is required when there is a group of related fields. But Tone's documentation encourages not having nested fieldsets and avoiding wrapping a lot set of fields in a single fieldset. To follow these recommendations on anything other than simple forms, we would have to not use this base form component.

@woodseowl
Copy link
Collaborator

I was working on trying to use these and realized there isn't a textarea input. Seems like that should be in our standard collection?

Comment on lines +81 to +83
<x-cd.form.checkbox label="Subscription" wire:model.live="subscribe"/>
Subscribe
</x-cd-form.checkbox>
Copy link
Collaborator

@woodseowl woodseowl Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<x-cd.form.checkbox label="Subscription" wire:model.live="subscribe"/>
Subscribe
</x-cd-form.checkbox>
<x-cd.form.checkbox label="Subscription" wire:model.live="subscribe">
Subscribe
</x-cd.form.checkbox>

Typo

@@ -0,0 +1,181 @@
# Form Components

A set of form components provides support the the styled form elements in the CD Framework.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A set of form components provides support the the styled form elements in the CD Framework.
A set of form components provides support for the styled form elements in the CD Framework.

Typo

Copy link
Collaborator

@woodseowl woodseowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple small things I found building forms based on the docs

Comment on lines +74 to +76
<x-cd.form.checkbox label="Subscription" text="Subscribe"
wire:model.live="subscribe"
/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either this example should include something like a value='1' attribute or cd.form.checkbox should default $value, because this as written results in an undefined variable.

```
<x-cd.form.radios label="Radios" wire:model.live="radios" :radiobuttons="$radiooptions" />
```
Using `inline=1` alows the radio buttons to be displayed inline with flexbox.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find evidence of this feature actually existing, but it would be great to have!

```
<x-cd.form.submit-button />
<x-cd.form.reset-button />
<x-cd.form.cancel-button wire:click"closemodal">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<x-cd.form.cancel-button wire:click"closemodal">
<x-cd.form.cancel-button wire:click="closemodal" />

Typo

Comment on lines +9 to +10
<x-slot name="field_title">{!! $label !!}</x-slot>
<div class="flex-grid compact-rows">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you think of putting $slot between these:

Suggested change
<x-slot name="field_title">{!! $label !!}</x-slot>
<div class="flex-grid compact-rows">
<x-slot name="field_title">{!! $label !!}</x-slot>
{!! $slot !!}
<div class="flex-grid compact-rows">

That would make it possible to include content between the heading and the options, like in the "A Plethora of Checkboxes" example

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