generated from gravity-ui/package-example
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added accordeon card to config (#162)
Authored-by: Aleksei <[email protected]>
- Loading branch information
1 parent
2fd9531
commit ab23f6c
Showing
50 changed files
with
343 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
7 changes: 7 additions & 0 deletions
7
src/lib/kit/components/Layouts/AccordeonCard/AccordeonCardForm.scss
This file contains 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,7 @@ | ||
@import '../../../styles/variables.scss'; | ||
|
||
.#{$ns}accordeon-card-form { | ||
&__accordeon-card-body { | ||
padding-right: 32px; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/lib/kit/components/Layouts/AccordeonCard/AccordeonCardForm.tsx
This file contains 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,53 @@ | ||
import React from 'react'; | ||
|
||
import {ArrayLayoutProps, ObjectLayoutProps} from '../../../../core'; | ||
import {useErrorChecker} from '../../../hooks'; | ||
import {block} from '../../../utils'; | ||
import {AccordeonCard} from '../../AccordeonCard'; | ||
import {ErrorWrapper} from '../../ErrorWrapper'; | ||
import {RemoveButton} from '../../RemoveButton'; | ||
|
||
import './AccordeonCardForm.scss'; | ||
|
||
const b = block('accordeon-card-form'); | ||
|
||
export const AccordeonCardForm = <T extends ArrayLayoutProps | ObjectLayoutProps>({ | ||
name, | ||
spec, | ||
input, | ||
children, | ||
meta, | ||
}: T): JSX.Element => { | ||
const [open, setOpen] = React.useState(Boolean(spec.viewSpec?.layoutOpen)); | ||
|
||
const onDrop = React.useCallback(() => { | ||
setOpen(false); | ||
input.onDrop(); | ||
}, [input.onDrop, setOpen]); | ||
|
||
const removeButton = React.useMemo(() => { | ||
if (spec.required || !input.value) { | ||
return null; | ||
} | ||
|
||
return <RemoveButton name={name} onDrop={onDrop} />; | ||
}, [spec.required, input.value, onDrop, name]); | ||
|
||
useErrorChecker({name, meta, open, setOpen}); | ||
|
||
return ( | ||
<AccordeonCard | ||
classNameBody={b('accordeon-card-body')} | ||
name={name} | ||
header={spec.viewSpec.layoutTitle || ''} | ||
description={spec.viewSpec.layoutDescription || ''} | ||
open={open} | ||
onToggle={setOpen} | ||
headerActionsTemplate={removeButton} | ||
> | ||
<ErrorWrapper name={name} meta={meta} withoutChildErrorStyles> | ||
{children} | ||
</ErrorWrapper> | ||
</AccordeonCard> | ||
); | ||
}; |
Binary file added
BIN
+19.2 KB
...sual.test.tsx-snapshots/Accordeon-Card-Form-object-spec-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.8 KB
...visual.test.tsx-snapshots/Accordeon-Card-Form-object-spec-dark-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.1 KB
...ual.test.tsx-snapshots/Accordeon-Card-Form-object-spec-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.5 KB
...isual.test.tsx-snapshots/Accordeon-Card-Form-object-spec-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.1 KB
...apshots/Accordeon-Card-Form-test-array-specs-array-spec-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+14.8 KB
...snapshots/Accordeon-Card-Form-test-array-specs-array-spec-dark-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.9 KB
...pshots/Accordeon-Card-Form-test-array-specs-array-spec-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+14.5 KB
...napshots/Accordeon-Card-Form-test-array-specs-array-spec-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+37.8 KB
...pshots/Accordeon-Card-Form-test-array-specs-description-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+29 KB
...napshots/Accordeon-Card-Form-test-array-specs-description-dark-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+37.4 KB
...shots/Accordeon-Card-Form-test-array-specs-description-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+28.7 KB
...apshots/Accordeon-Card-Form-test-array-specs-description-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+46.3 KB
...s/Accordeon-Card-Form-test-array-specs-error-max-length-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+34.7 KB
...ots/Accordeon-Card-Form-test-array-specs-error-max-length-dark-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+46.4 KB
.../Accordeon-Card-Form-test-array-specs-error-max-length-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+34.9 KB
...ts/Accordeon-Card-Form-test-array-specs-error-max-length-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.3 KB
...s/Accordeon-Card-Form-test-array-specs-error-min-length-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16 KB
...ots/Accordeon-Card-Form-test-array-specs-error-min-length-dark-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.8 KB
.../Accordeon-Card-Form-test-array-specs-error-min-length-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16.5 KB
...ts/Accordeon-Card-Form-test-array-specs-error-min-length-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+34 KB
...snapshots/Accordeon-Card-Form-test-array-specs-required-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+25.9 KB
...x-snapshots/Accordeon-Card-Form-test-array-specs-required-dark-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+33.5 KB
...napshots/Accordeon-Card-Form-test-array-specs-required-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+25.6 KB
...-snapshots/Accordeon-Card-Form-test-array-specs-required-light-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16 KB
...isual.test.tsx-snapshots/Accordeon-Card-View-array-spec-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.7 KB
....visual.test.tsx-snapshots/Accordeon-Card-View-array-spec-dark-webkit-linux.png
Oops, something went wrong.
Binary file added
BIN
+16.1 KB
...sual.test.tsx-snapshots/Accordeon-Card-View-array-spec-light-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+12.5 KB
...visual.test.tsx-snapshots/Accordeon-Card-View-array-spec-light-webkit-linux.png
Oops, something went wrong.
Binary file added
BIN
+15.6 KB
...sual.test.tsx-snapshots/Accordeon-Card-View-object-spec-dark-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+13.3 KB
...visual.test.tsx-snapshots/Accordeon-Card-View-object-spec-dark-webkit-linux.png
Oops, something went wrong.
Binary file added
BIN
+15.7 KB
...ual.test.tsx-snapshots/Accordeon-Card-View-object-spec-light-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+13.2 KB
...isual.test.tsx-snapshots/Accordeon-Card-View-object-spec-light-webkit-linux.png
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
src/lib/kit/components/Layouts/AccordeonCard/__tests__/AccordeonCard.visual.test.tsx
This file contains 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,65 @@ | ||
import React from 'react'; | ||
|
||
import {ACCORDEON_CARD, VALUE} from './helpers'; | ||
|
||
import {test} from '~playwright/core'; | ||
import {DynamicForm} from '~playwright/core/DynamicForm'; | ||
import {DynamicView} from '~playwright/core/DynamicView'; | ||
|
||
test.describe('Accordeon Card Form', () => { | ||
test.describe('test array specs', () => { | ||
test('array spec', async ({mount, expectScreenshot}) => { | ||
await mount(<DynamicForm spec={ACCORDEON_CARD.arraySpec} />); | ||
|
||
await expectScreenshot(); | ||
}); | ||
|
||
test('required', async ({mount, expectScreenshot}) => { | ||
await mount(<DynamicForm spec={ACCORDEON_CARD.required} />); | ||
|
||
await expectScreenshot(); | ||
}); | ||
|
||
test('error max length', async ({mount, expectScreenshot}) => { | ||
const component = await mount(<DynamicForm spec={ACCORDEON_CARD.errorMaxLength} />); | ||
|
||
await component.getByText('Add element').click(); | ||
|
||
await expectScreenshot(); | ||
}); | ||
|
||
test('error min length', async ({mount, expectScreenshot}) => { | ||
const component = await mount(<DynamicForm spec={ACCORDEON_CARD.errorMinLength} />); | ||
|
||
await component.getByText('Add element').click(); | ||
|
||
await expectScreenshot(); | ||
}); | ||
|
||
test('description', async ({mount, expectScreenshot}) => { | ||
await mount(<DynamicForm spec={ACCORDEON_CARD.description} />); | ||
|
||
await expectScreenshot(); | ||
}); | ||
}); | ||
|
||
test('object spec', async ({mount, expectScreenshot}) => { | ||
await mount(<DynamicForm spec={ACCORDEON_CARD.objectSpec} />); | ||
|
||
await expectScreenshot(); | ||
}); | ||
}); | ||
|
||
test.describe('Accordeon Card View', () => { | ||
test('array spec', async ({mount, expectScreenshot}) => { | ||
await mount(<DynamicView spec={ACCORDEON_CARD.arraySpec} value={VALUE.array} />); | ||
|
||
await expectScreenshot(); | ||
}); | ||
|
||
test('object spec', async ({mount, expectScreenshot}) => { | ||
await mount(<DynamicView spec={ACCORDEON_CARD.objectSpec} value={VALUE.object} />); | ||
|
||
await expectScreenshot(); | ||
}); | ||
}); |
151 changes: 151 additions & 0 deletions
151
src/lib/kit/components/Layouts/AccordeonCard/__tests__/helpers.ts
This file contains 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,151 @@ | ||
import {ArraySpec, FormValue, ObjectSpec, SpecTypes} from '../../../../../core'; | ||
|
||
export const ACCORDEON_CARD: Record<string, ArraySpec | ObjectSpec> = { | ||
arraySpec: { | ||
defaultValue: ['value'], | ||
type: SpecTypes.Array, | ||
items: { | ||
type: SpecTypes.String, | ||
viewSpec: { | ||
type: 'base', | ||
layout: 'row', | ||
layoutTitle: 'Element', | ||
}, | ||
}, | ||
viewSpec: { | ||
type: 'base', | ||
layout: 'accordeon_card', | ||
layoutTitle: 'Accordeon Card', | ||
layoutOpen: true, | ||
itemLabel: 'Add element', | ||
}, | ||
}, | ||
required: { | ||
required: true, | ||
defaultValue: ['foo', 'bar', 'rab', 'oof'], | ||
type: SpecTypes.Array, | ||
items: { | ||
type: SpecTypes.String, | ||
viewSpec: { | ||
type: 'base', | ||
layout: 'row', | ||
layoutTitle: 'Element', | ||
}, | ||
}, | ||
viewSpec: { | ||
type: 'base', | ||
layout: 'accordeon_card', | ||
layoutTitle: 'Elements', | ||
layoutOpen: true, | ||
itemLabel: 'Add element', | ||
}, | ||
}, | ||
errorMaxLength: { | ||
maxLength: BigInt(4), | ||
defaultValue: ['foo', 'bar', 'rab', 'oof'], | ||
type: SpecTypes.Array, | ||
items: { | ||
type: SpecTypes.String, | ||
viewSpec: { | ||
type: 'base', | ||
layout: 'row', | ||
layoutTitle: 'Element', | ||
}, | ||
}, | ||
viewSpec: { | ||
type: 'base', | ||
layout: 'accordeon_card', | ||
layoutTitle: 'Elements', | ||
layoutOpen: true, | ||
itemLabel: 'Add element', | ||
}, | ||
}, | ||
errorMinLength: { | ||
minLength: BigInt(4), | ||
type: SpecTypes.Array, | ||
items: { | ||
type: SpecTypes.String, | ||
viewSpec: { | ||
type: 'base', | ||
layout: 'row', | ||
layoutTitle: 'Element', | ||
}, | ||
}, | ||
viewSpec: { | ||
type: 'base', | ||
layout: 'accordeon_card', | ||
layoutTitle: 'Elements', | ||
layoutOpen: true, | ||
itemLabel: 'Add element', | ||
}, | ||
}, | ||
description: { | ||
defaultValue: ['foo', 'bar', 'rab', 'oof'], | ||
type: SpecTypes.Array, | ||
items: { | ||
type: SpecTypes.String, | ||
viewSpec: { | ||
type: 'base', | ||
layout: 'row', | ||
layoutTitle: 'Element', | ||
}, | ||
}, | ||
viewSpec: { | ||
type: 'base', | ||
layout: 'accordeon_card', | ||
layoutTitle: 'Elements', | ||
layoutDescription: 'description', | ||
layoutOpen: true, | ||
itemLabel: 'Add element', | ||
}, | ||
}, | ||
objectSpec: { | ||
defaultValue: { | ||
name: 'value', | ||
age: 10, | ||
license: false, | ||
}, | ||
type: SpecTypes.Object, | ||
properties: { | ||
name: { | ||
type: SpecTypes.String, | ||
viewSpec: { | ||
type: 'base', | ||
layout: 'row', | ||
layoutTitle: 'Name', | ||
}, | ||
}, | ||
age: { | ||
type: SpecTypes.Number, | ||
viewSpec: { | ||
type: 'base', | ||
layout: 'row', | ||
layoutTitle: 'Age', | ||
}, | ||
}, | ||
license: { | ||
type: SpecTypes.Boolean, | ||
viewSpec: { | ||
type: 'base', | ||
layout: 'row', | ||
layoutTitle: 'License', | ||
}, | ||
}, | ||
}, | ||
viewSpec: { | ||
type: 'base', | ||
layout: 'accordeon_card', | ||
layoutTitle: 'Candidate', | ||
layoutOpen: true, | ||
}, | ||
}, | ||
}; | ||
|
||
export const VALUE: Record<string, FormValue> = { | ||
array: ['value', 'value'], | ||
object: { | ||
name: 'name', | ||
age: 21, | ||
license: true, | ||
}, | ||
}; |
This file contains 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 @@ | ||
export * from './AccordeonCardForm'; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 @@ | ||
export * from './RemoveButton'; |
Oops, something went wrong.