Skip to content

Commit b1106aa

Browse files
committed
fix: warnings and errors
1 parent 1031811 commit b1106aa

File tree

12 files changed

+77
-63
lines changed

12 files changed

+77
-63
lines changed

.changeset/lucky-beans-crash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cube-dev/ui-kit': patch
3+
---
4+
5+
Fix pressed state in primary type Button.

src/components/actions/Button/Button.stories.tsx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@ export default {
1515
defaultValue: undefined,
1616
control: { type: 'radio', options: [undefined, 'small', 'large'] },
1717
},
18-
type: {
19-
defaultValue: undefined,
20-
control: {
21-
type: 'radio',
22-
options: [
23-
undefined,
24-
'secondary',
25-
'primary',
26-
'outline',
27-
'clear',
28-
'neutral',
29-
'link',
30-
],
31-
},
32-
},
18+
// @TODO: Migrate to new API
19+
// type: {
20+
// defaultValue: undefined,
21+
// control: {
22+
// type: 'radio',
23+
// options: [
24+
// undefined,
25+
// 'secondary',
26+
// 'primary',
27+
// 'outline',
28+
// 'clear',
29+
// 'neutral',
30+
// 'link',
31+
// ],
32+
// },
33+
// },
3334
theme: {
3435
defaultValue: undefined,
3536
control: { type: 'radio', options: [undefined, 'danger', 'special'] },

src/components/actions/Button/Button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ const ButtonElement = tasty({
118118
'': '#clear',
119119

120120
'[data-type="primary"]': '#purple',
121-
'[data-type="primary"] & pressed': '#purple',
122121
'[data-type="primary"] & hovered': '#purple-text',
122+
'[data-type="primary"] & pressed': '#purple',
123123

124124
'[data-type="secondary"]': '#purple.10',
125125
'[data-type="secondary"] & hovered': '#purple.16',

src/components/fields/TextInputMapper/TextInputMapper.stories.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { StoryFn } from '@storybook/react';
22
import { userEvent, within } from '@storybook/test';
33

44
import { baseProps } from '../../../stories/lists/baseProps';
5-
import { SubmitButton } from '../../actions';
65
import { Form } from '../../form';
76
import { TextInput } from '../TextInput/index';
87

@@ -39,7 +38,7 @@ const FormTemplate: StoryFn<CubeTextInputMapperProps> = ({ ...props }) => (
3938
{...props}
4039
onChange={(value) => console.log('! onChange', value)}
4140
/>
42-
<SubmitButton>Submit</SubmitButton>
41+
<Form.Submit>Submit</Form.Submit>
4342
</Form>
4443
);
4544

@@ -56,7 +55,7 @@ const FormTemplateSync: StoryFn<CubeTextInputMapperProps> = ({ ...props }) => (
5655
onChange={(value) => console.log('! onChange', value)}
5756
/>
5857
<TextInput name="field.name" label="TextInput" />
59-
<SubmitButton>Submit</SubmitButton>
58+
<Form.Submit>Submit</Form.Submit>
6059
</Form>
6160
);
6261

src/components/form/Form/ComplexForm.stories.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { userEvent, waitFor, within } from '@storybook/test';
44
import { expect } from '@storybook/test';
55

66
import {
7-
Alert,
87
Block,
98
Checkbox,
109
CheckboxGroup,
@@ -17,18 +16,17 @@ import {
1716
RangeSlider,
1817
Slider,
1918
Select,
20-
SubmitButton,
21-
SubmitError,
2219
Switch,
2320
DateInput,
2421
TextInput,
2522
NumberInput,
2623
parseAbsoluteDate,
2724
FileInput,
25+
Space,
26+
Button,
2827
} from '../../../index';
2928
// import { NumberInput } from '../NumberInput/NumberInput';
3029
import { baseProps } from '../../../stories/lists/baseProps';
31-
import { Button } from '../../actions/index';
3230
import { timeout } from '../../../utils/promise';
3331

3432
export default {
@@ -69,8 +67,8 @@ export default {
6967
// >
7068
// <TextInput />
7169
// </Field>
72-
// <Submit>Submit</Submit>
73-
// <SubmitError />
70+
// <Form.Submit>Submit</Form.Submit>
71+
// <Form.SubmitError />
7472
// </Form>
7573
// );
7674
// };
@@ -94,8 +92,8 @@ const CustomSubmitErrorTemplate: StoryFn<typeof Form> = (args) => {
9492
<Field name="text" label="Text input">
9593
<TextInput />
9694
</Field>
97-
<SubmitButton>Submit</SubmitButton>
98-
{form.submitError ? <Alert>{form.submitError as string}</Alert> : null}
95+
<Form.Submit>Submit</Form.Submit>
96+
<Form.SubmitError />
9997
</Form>
10098
);
10199
};
@@ -119,8 +117,8 @@ const SubmitErrorTemplate: StoryFn<typeof Form> = (args) => {
119117
<Field name="text" label="Text input">
120118
<TextInput />
121119
</Field>
122-
<SubmitButton>Submit</SubmitButton>
123-
<SubmitError />
120+
<Form.Submit>Submit</Form.Submit>
121+
<Form.SubmitError />
124122
</Form>
125123
);
126124
};
@@ -161,7 +159,10 @@ const AsyncValidationTemplate: StoryFn<typeof Form> = (args) => {
161159
>
162160
<TextInput />
163161
</Field>
164-
<SubmitButton>Submit</SubmitButton>
162+
<Space>
163+
<Form.Submit>Submit</Form.Submit>
164+
<Form.Reset>Reset</Form.Reset>
165+
</Space>
165166
</Form>
166167
);
167168
};
@@ -269,7 +270,6 @@ const Template: StoryFn<typeof Form> = (args) => {
269270
},
270271
]}
271272
necessityIndicator={'label'}
272-
defaultValue="[email protected]"
273273
shouldUpdate={({ email }) => {
274274
return !!email;
275275
}}
@@ -353,7 +353,10 @@ const Template: StoryFn<typeof Form> = (args) => {
353353
>
354354
<RangeSlider minValue={0} maxValue={100} />
355355
</Field>
356-
<SubmitButton>Submit</SubmitButton>
356+
<Space>
357+
<Form.Submit>Submit</Form.Submit>
358+
<Form.Reset>Reset</Form.Reset>
359+
</Space>
357360
</Form>
358361
</>
359362
);

src/components/form/Form/ResetButton/ResetButton.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,16 @@ function ResetButton(
3535
type="primary"
3636
htmlType="reset"
3737
isDisabled={form?.isSubmitting || !form?.isTouched}
38-
{...mergeProps({ onPress, isDisabled }, otherProps)}
38+
{...mergeProps(
39+
{
40+
onPress,
41+
isDisabled:
42+
isDisabled != null
43+
? isDisabled
44+
: form?.isSubmitting || !form?.isTouched,
45+
},
46+
otherProps,
47+
)}
3948
/>
4049
);
4150
}

src/components/form/Form/SubmitButton/SubmitButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function SubmitButton(
3232
type="primary"
3333
htmlType="submit"
3434
isLoading={form?.isSubmitting}
35-
isDisabled={!form?.isInvalid || isDisabled}
35+
isDisabled={isDisabled != null ? isDisabled : form?.isInvalid}
3636
{...otherProps}
3737
/>
3838
);

src/components/form/Form/SubmitError.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ type SubmitErrorContextProps = {
1414
submitError?: unknown;
1515
};
1616

17-
const SubmitError = function SubmitError(
18-
props: CubeAlertProps,
19-
ref: ForwardedRef<HTMLDivElement>,
20-
) {
17+
function SubmitError(props: CubeAlertProps, ref: ForwardedRef<HTMLDivElement>) {
2118
let { submitError } = useContext(FormContext) as SubmitErrorContextProps;
2219

2320
if (!submitError) {
@@ -36,7 +33,7 @@ const SubmitError = function SubmitError(
3633
{submitError as ReactNode}
3734
</Alert>
3835
);
39-
};
36+
}
4037

4138
/**
4239
* An alert that shows a form error message received from the onSubmit callback.

src/components/form/Form/index.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,21 @@ const Form = Object.assign(
1515
Reset: typeof ResetButton;
1616
useForm: typeof useForm;
1717
},
18-
{ Item: Field, useForm, SubmitButton, ResetButton, SubmitError },
18+
{
19+
Item: Field,
20+
useForm,
21+
Submit: SubmitButton,
22+
Reset: ResetButton,
23+
SubmitError,
24+
},
1925
);
2026

21-
export {
22-
useFormProps,
23-
Form,
24-
Field,
25-
useForm,
26-
FormContext,
27-
SubmitError,
28-
SubmitButton,
29-
ResetButton,
30-
};
31-
export { useFieldProps } from './use-field/index';
27+
export * from './SubmitError';
28+
export * from './SubmitButton';
29+
export * from './ResetButton';
30+
export * from './use-field';
31+
export { useFormProps, Form, Field, useForm, FormContext };
3232
export type { CubeFormProps } from './Form';
3333
export type { CubeFormInstance } from './use-form';
3434
export type { FieldTypes, Fields } from './types';
35-
export type { UseFieldParams, UseFieldPropsParams } from './use-field/index';
3635
export type { CubeAlertProps as CubeSubmitErrorProps };
37-
export type { CubeResetButtonProps } from './ResetButton';
38-
export type { CubeSubmitButtonProps } from './SubmitButton';

src/components/form/Form/submit-error.test.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import userEvents from '@testing-library/user-event';
22
import { waitFor, act } from '@testing-library/react';
33

44
import { renderWithForm } from '../../../test/index';
5-
import { SubmitButton } from '../../form';
6-
import { TextInput } from '../../fields/TextInput';
5+
import { TextInput } from '../../fields';
76

87
import { Form } from './index';
98

@@ -16,7 +15,7 @@ describe('<SubmitError />', () => {
1615
<>
1716
<TextInput name="test" label="Test" />
1817

19-
<SubmitButton>Submit</SubmitButton>
18+
<Form.Submit>Submit</Form.Submit>
2019

2120
<Form.SubmitError />
2221
</>,
@@ -53,7 +52,7 @@ describe('<SubmitError />', () => {
5352
<>
5453
<TextInput name="test" label="Test" />
5554

56-
<SubmitButton>Submit</SubmitButton>
55+
<Form.Submit>Submit</Form.Submit>
5756

5857
<Form.SubmitError />
5958
</>,
@@ -101,7 +100,7 @@ describe('<SubmitError />', () => {
101100
<>
102101
<TextInput name="test" label="Test" />
103102

104-
<SubmitButton>Submit</SubmitButton>
103+
<Form.Submit>Submit</Form.Submit>
105104

106105
<Form.SubmitError />
107106
</>,

0 commit comments

Comments
 (0)