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

feat(Forms): add Form.Card with different default appearance than Card (use Form.Card in forms instead of Card) #4318

Merged
merged 10 commits into from
Nov 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ The `InputPassword` component has been moved to `Field.Password`, and is now a p
- replace `useError` with `useValidation`.
- replace Form.Iterate label variable `{itemNr}` with `{itemNo}`.
- replace `Form.FieldProps` with `Field.Provider`.
- replace `<Card stack>...</Card>` with `<Form.Card>...</Form.Card>`.
- replace `<Card>...</Card>` with `<Form.Card>...</Form.Card>`.

tujoworker marked this conversation as resolved.
Show resolved Hide resolved
## NumberFormat

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
Flex,
Grid,
H2,
Hr,
P,
Section,
Table,
Expand Down Expand Up @@ -172,10 +171,8 @@ export const Stack = () => {
return (
<ComponentBox data-visual-test="layout-card-stack">
<Card stack>
<Field.String label="Label" value="Value" />
<Field.String label="Label" value="Value" />
<Hr />
<Form.SubmitButton />
<P>Stacked content</P>
<P>Stacked content</P>
</Card>
</ComponentBox>
)
Expand All @@ -184,25 +181,25 @@ export const Stack = () => {
export const VerticalFields = () => {
return (
<ComponentBox>
<Card>
<Form.Card>
<Flex.Vertical>
<Field.String label="Label" value="Value" />
<Field.String label="Label" value="Value" />
</Flex.Vertical>
</Card>
</Form.Card>
</ComponentBox>
)
}

export const HorizontalFields = () => {
return (
<ComponentBox>
<Card>
<Form.Card>
<Flex.Horizontal>
<Field.String label="Label" value="Value" width="small" />
<Field.String label="Label" value="Value" width="stretch" />
</Flex.Horizontal>
</Card>
</Form.Card>
</ComponentBox>
)
}
Expand Down Expand Up @@ -275,14 +272,14 @@ export const WithOutset = () => {
return (
<ComponentBox data-visual-test="layout-card-outset">
<Flex.Vertical>
<Form.MainHeading>Main heading</Form.MainHeading>
<Form.MainHeading>I'm left aligned</Form.MainHeading>
<Card stack outset>
<P>Card content</P>
<Card>
<P>Nested card</P>
</Card>
</Card>
<Form.SubmitButton />
<Form.SubmitButton text="I'm also left aligned" />
</Flex.Vertical>
</ComponentBox>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ import * as Examples from './Examples'

### Vertical fields

When using Eufemia Forms, you may want to use [Form.Card](/uilib/extensions/forms/Form/Card/) instead of the original Card component.

<Examples.VerticalFields />

### Horizontal fields

When using Eufemia Forms, you may want to use [Form.Card](/uilib/extensions/forms/Form/Card/) instead of the original Card component.

<Examples.HorizontalFields />

### Stack

The Card components needs to have `stack={true}` or `align="stretch"` in order to stretch its children components.
When `stack` is set to `true`, the Card will add a gap between its children and stretch them to the full.

For [form components](uilib/extensions/forms/), you should use [Form.Card](/uilib/extensions/forms/Form/Card/) instead of the original Card component.

For [form components](uilib/extensions/forms/), you should use `stack={true}` to get the correct spacing.
When `stack` is set to `true`, the Card will add a gap between its children and stretch them to the full.
tujoworker marked this conversation as resolved.
Show resolved Hide resolved

<Examples.Stack />

Expand All @@ -34,6 +40,7 @@ Nested cards have `responsive={false}` by default and will not behave responsive

## With `outset`

When using `outset`, the Card will break out of the layout container.
On small screens (mobile) the outset is removed.

<Examples.WithOutset />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from 'react'
import ComponentBox from '../../../../shared/tags/ComponentBox'
import styled from '@emotion/styled'
import { Textarea, HelpButton, Flex, Card } from '@dnb/eufemia/src'
import { Textarea, HelpButton, Flex } from '@dnb/eufemia/src'
import { Field, Form } from '@dnb/eufemia/src/extensions/forms'

export const RowsCols = () => (
Expand Down Expand Up @@ -154,7 +154,7 @@ export const MaxLength = () => (
<Wrapper>
<ComponentBox hideCode>
<Form.Handler>
<Card stack>
<Form.Card>
<Field.String
label="Label"
placeholder="Write more than 3 characters to demonstrate the limit"
Expand All @@ -164,7 +164,7 @@ export const MaxLength = () => (
characterCounter={{ max: 3, variant: 'up' }}
/>
<Form.SubmitButton text="Test" />
</Card>
</Form.Card>
</Form.Handler>
</ComponentBox>
</Wrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Value,
JSONSchema,
} from '@dnb/eufemia/src/extensions/forms'
import { Card, Flex } from '@dnb/eufemia/src'
import { Flex } from '@dnb/eufemia/src'

export const TestdataSchema: JSONSchema = {
type: 'object',
Expand Down Expand Up @@ -102,7 +102,7 @@ export const Default = () => {
sessionStorageId="provider-example-1"
>
<Flex.Stack>
<Card stack>
<Form.Card>
<Flex.Vertical divider="line" gap="small">
<Field.String
path="/requiredString"
Expand Down Expand Up @@ -164,7 +164,7 @@ export const Default = () => {
<Form.SubmitButton />
</Form.ButtonRow>
</Flex.Vertical>
</Card>
</Form.Card>
</Flex.Stack>
</DataContext.Provider>
</ComponentBox>
Expand Down Expand Up @@ -192,7 +192,7 @@ export const ValidationWithJsonSchema = () => {
onSubmitRequest={() => console.log('onSubmitRequest')}
>
<Flex.Stack>
<Card stack>
<Form.Card>
<Flex.Vertical divider="line" gap="small">
<Field.String
path="/requiredString"
Expand Down Expand Up @@ -252,7 +252,7 @@ export const ValidationWithJsonSchema = () => {
<Form.SubmitButton />
</Form.ButtonRow>
</Flex.Vertical>
</Card>
</Form.Card>
</Flex.Stack>
</DataContext.Provider>
</ComponentBox>
Expand Down
Loading
Loading