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

Implement editgrid (repeating groups) - part 1 #85

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

sergei-maertens
Copy link
Member

@sergei-maertens sergei-maertens commented Mar 11, 2025

Closes #36 (partly)

  • Added Formik primitives and markup/styling for edit grid, mostly ported from the SDK
  • Added an initial abstraction for icons, anticipating custom icon libraries in the future

This an almost verbatim copy of the EditGrid components, with some
re-organized SCSS and improved documentation.
It's a bit annoying that the icon library leaks down into everything,
but for the time being we're not planning on supporting other icons.

It would be possible to refactor this in the future to make it more
pluggable, so the code to include an icon will be generalized a bit
to make that clear.

It's up to the downstream project to ensure the necessary stylesheets
are loaded - we leave that out of scope because the complexities of
font assets paths are a headache.
For the time being, we stick to font-awesome, but it should possible
in the future to bring in your own SVG-based icons to render or
alternative libraries, so the Icon component has been named in a
generic way to make future expansion more natural.

Plenty of challenges there that we will *not* tackle right now.
The editgrid state is now encapsulated in FieldArray, which provides the
helpers to update/replace individual items at a particular index and/or
remove them. It's up to the developer to still properly provide the
array of items, using the same source of form state, but this allows
automatic wrapping in EditGridItem components so that the implementation
details don't have to leak to the outside too much.

This actually unlocks a new feature where we can make per-item decisions
about which controls for saving/removing are available, a thing we need
for the appointment flow with products where you cannot remove the only
product if there's only one.

To enable adding items, only a blueprint/blank item needs to be provided
as a prop (which can also change depending on the state, that's up to
the outer component). Providing `null` for this blueprint disables the
add button.
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.

Implement repeating group (editgrid)
1 participant