[feat]: Implement form theme (#69)

This commit is contained in:
Fazza Razaq Amiarso 2022-10-08 02:23:32 +07:00 committed by GitHub
parent ef779de6d4
commit 1491135302
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 9 deletions

View file

@ -6,12 +6,15 @@ import FieldSet from './components/FieldSet.astro';
export interface Props {
submitControl?: Submit;
formGroups: FormGroup[];
theme?: "light" | "dark";
}
const { submitControl, formGroups } = Astro.props;
const { submitControl, formGroups, theme } = Astro.props;
const formTheme = theme ?? "light";
---
<form class="light">
<form class={formTheme}>
{formGroups?.map((group) => <FieldSet group={group} />)}
{submitControl && <Field control={new FormControl(submitControl)} />}
</form>

View file

@ -1,4 +1,5 @@
import { expect } from 'chai';
import { describe, beforeEach, it } from 'mocha';
import { getComponentOutput } from 'astro-component-tester';
describe('Form.astro test', () => {
@ -44,12 +45,14 @@ describe('Form.astro test', () => {
const expectedCount = 3;
const element = /<fieldset>/g;
const fakeFormGroup = {
controls: [{
type: 'checkbox',
name: 'fake-checkbox',
label: 'FAKE CHECKBOX'
}]
}
controls: [
{
type: 'checkbox',
name: 'fake-checkbox',
label: 'FAKE CHECKBOX',
},
],
};
const props = { formGroups: Array(expectedCount).fill(fakeFormGroup) };
component = await getComponentOutput('./Form.astro', props);
@ -59,7 +62,7 @@ describe('Form.astro test', () => {
// assert
expect(matches.length).to.equal(expectedCount);
})
});
});
});