-
Notifications
You must be signed in to change notification settings - Fork 1
IBX-10573: Shared base for form control list components #24
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| @use 'functions' as *; | ||
|
|
||
| .ids-choice-inputs-list { | ||
| $self: &; | ||
|
|
||
| .ids-form-control { | ||
| &__label-wrapper { | ||
| margin-bottom: calculateRem(4px); | ||
| } | ||
|
|
||
| &__helper-text-wrapper { | ||
| margin-top: calculateRem(4px); | ||
| } | ||
| } | ||
|
|
||
| &__items { | ||
| display: flex; | ||
| flex-direction: column; | ||
|
|
||
| & > * { | ||
| padding: calculateRem(4px) calculateRem(8px); | ||
| } | ||
| } | ||
|
|
||
| &--horizontal { | ||
| #{$self}__items { | ||
| flex-direction: row; | ||
| flex-wrap: wrap; | ||
| gap: calculateRem(12px); | ||
|
|
||
| & > * { | ||
| padding: calculateRem(4px) 0; | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
packages/components/src/internal/partials/BaseInputsList/BaseInputsList.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import React from 'react'; | ||
|
|
||
| import type { Meta, StoryObj } from '@storybook/react'; | ||
|
|
||
| import BaseInputsList from './BaseInputsList'; | ||
| import { DIRECTION } from './BaseInputsList.types'; | ||
|
|
||
| interface ItemType { | ||
| id: string; | ||
| label: string; | ||
| } | ||
|
|
||
| const meta: Meta<typeof BaseInputsList<ItemType>> = { | ||
| title: 'components/src/base/BaseInputsList', | ||
| component: BaseInputsList<ItemType>, | ||
| parameters: { | ||
| layout: 'centered', | ||
| docs: { | ||
| controls: { exclude: ['items', 'renderItem', 'labelProps', 'helperTextProps'] }, | ||
| }, | ||
| }, | ||
| tags: ['autodocs', 'foundation', 'base'], | ||
| argTypes: { | ||
| className: { control: 'text' }, | ||
| direction: { | ||
| control: 'select', | ||
| options: Object.values(DIRECTION), | ||
| }, | ||
| }, | ||
| args: { | ||
| items: [ | ||
| { id: '1', label: 'Item 1' }, | ||
| { id: '2', label: 'Item 2' }, | ||
| { id: '3', label: 'Item 3' }, | ||
| ], | ||
| renderItem: (item: ItemType) => ( | ||
| <div key={item.id}> | ||
| {item.id}: {item.label} | ||
| </div> | ||
| ), | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof BaseInputsList<ItemType>>; | ||
|
|
||
| export const Default: Story = { | ||
| name: 'Default', | ||
| args: { | ||
| labelProps: { children: 'Choice Inputs List Label' }, | ||
| helperTextProps: { children: 'This is a helper text' }, | ||
| }, | ||
| }; | ||
|
|
||
| export const Horizontal: Story = { | ||
| name: 'Horizontal', | ||
| args: { | ||
| labelProps: { children: 'Choice Inputs List Label' }, | ||
| helperTextProps: { children: 'This is a helper text' }, | ||
| direction: DIRECTION.HORIZONTAL, | ||
| }, | ||
| }; | ||
|
|
||
| export const NoHelper: Story = { | ||
| name: 'No Helper', | ||
| args: { | ||
| labelProps: { children: 'Choice Inputs List Label' }, | ||
| }, | ||
| }; | ||
|
|
||
| export const NoLabel: Story = { | ||
| name: 'No Label', | ||
| args: { | ||
| helperTextProps: { children: 'This is a helper text' }, | ||
| }, | ||
| }; | ||
|
|
||
| export const OnlyItems: Story = { | ||
| name: 'Only Items', | ||
| args: {}, | ||
| }; |
28 changes: 28 additions & 0 deletions
28
packages/components/src/internal/partials/BaseInputsList/BaseInputsList.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import React from 'react'; | ||
|
|
||
| import BaseFormControl from '@ids-internal/partials/BaseFormControl'; | ||
| import { createCssClassNames } from '@ibexa/ids-core/helpers/cssClassNames'; | ||
|
|
||
| import { BaseInputsListProps, DIRECTION } from './BaseInputsList.types'; | ||
|
|
||
| const BaseInputsList = <T,>({ | ||
| items, | ||
| renderItem, | ||
| className = '', | ||
| direction = DIRECTION.VERTICAL, | ||
| helperTextProps, | ||
| labelProps, | ||
| }: BaseInputsListProps<T>) => { | ||
| const listClassName = createCssClassNames({ | ||
| 'ids-choice-inputs-list': true, | ||
| [`ids-choice-inputs-list--${direction}`]: true, | ||
| [className]: true, | ||
| }); | ||
| return ( | ||
| <BaseFormControl className={listClassName} helperText={helperTextProps} label={labelProps} type="list"> | ||
| <div className="ids-choice-inputs-list__items">{items.map((item) => renderItem(item))}</div> | ||
| </BaseFormControl> | ||
| ); | ||
| }; | ||
|
|
||
| export default BaseInputsList; | ||
16 changes: 16 additions & 0 deletions
16
packages/components/src/internal/partials/BaseInputsList/BaseInputsList.types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { BaseComponentAriaAttributes } from '@ids-types/general'; | ||
| import { HelperTextProps } from '../../../HelperText/HelperText.types'; | ||
| import { LabelProps } from '../../../Label/Label.types'; | ||
|
|
||
| export enum DIRECTION { | ||
| HORIZONTAL = 'horizontal', | ||
| VERTICAL = 'vertical', | ||
| } | ||
|
|
||
| export interface BaseInputsListProps<T> extends BaseComponentAriaAttributes { | ||
| items: T[]; | ||
| renderItem: (item: T) => React.ReactNode; | ||
| direction?: DIRECTION; | ||
| helperTextProps?: HelperTextProps; | ||
| labelProps?: LabelProps; | ||
| } |
5 changes: 5 additions & 0 deletions
5
packages/components/src/internal/partials/BaseInputsList/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { BaseInputsListProps, DIRECTION } from './BaseInputsList.types'; | ||
| import BaseInputsList from './BaseInputsList'; | ||
|
|
||
| export default BaseInputsList; | ||
| export type { BaseInputsListProps, DIRECTION }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.