-
Notifications
You must be signed in to change notification settings - Fork 60
[UIK-5336][feedback-form] rewrite component to TS #3009
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
Open
slizhevskyv-semrush
wants to merge
6
commits into
release/v17
Choose a base branch
from
UIK-5336/rewrite-component-to-ts
base: release/v17
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c801ab0
[UIK-5336][feedback-form] rewrite component to TS
slizhevskyv-semrush d873ee9
[UIK-5336][feedback-form] rewrite component to TS
slizhevskyv-semrush ec40251
[UIK-5336][feedback-form] rewrite component to TS
slizhevskyv-semrush c7514a8
[UIK-5336][feedback-form] rewrite component to TS
slizhevskyv-semrush 09c18c1
[UIK-5336][feedback-form] type changes & small PR improvements
slizhevskyv-semrush 4c0af09
[UIK-5336][feedback-form] type changes & small PR improvements
slizhevskyv-semrush 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
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
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
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,63 @@ | ||
| import type { Box } from '@semcore/base-components'; | ||
| import type Button from '@semcore/button'; | ||
| import type { Intergalactic } from '@semcore/core'; | ||
| import type { NoticeSmart } from '@semcore/notice'; | ||
| import type { FormProps } from 'react-final-form'; | ||
|
|
||
| import type { NSFeedbackItem } from './component/feedback-item/FeedbackItem.type'; | ||
| import type { NSSubmitButton } from './component/submit-button/SubmitButton.type'; | ||
|
|
||
| declare namespace NSFeedbackForm { | ||
| type Props = Intergalactic.InternalTypings.RemoveIndexSignature<FormProps> & { | ||
| /** The event is called when the form is submitted */ | ||
| onSubmit: (values: any, form: any, callback?: (errors?: {}) => void) => {} | Promise<{}> | void; | ||
| /** | ||
| * The property is in charge of the spinner showing | ||
| * */ | ||
| loading?: boolean; | ||
| /** | ||
| * Color of container spinner; you can use your own color | ||
| */ | ||
| background?: string; | ||
| /** Spinner theme. There are several default themes or you can use your own color | ||
| * @default dark | ||
| **/ | ||
| theme?: 'dark' | 'invert' | string; | ||
| }; | ||
| type DefaultProps = { | ||
| onSubmit: () => void; | ||
| }; | ||
|
|
||
| namespace Item { | ||
| type Component = NSFeedbackItem.Component; | ||
| } | ||
|
|
||
| namespace Success { | ||
| type Component = typeof Box; | ||
| } | ||
|
|
||
| namespace Submit { | ||
| type Component = NSSubmitButton.Component; | ||
| } | ||
|
|
||
| namespace Cancel { | ||
| type Component = typeof Button; | ||
| } | ||
|
|
||
| namespace Notice { | ||
| type Component = typeof NoticeSmart; | ||
| } | ||
|
|
||
| type Component = Intergalactic.Component<'form', Props> & { | ||
| Item: Item.Component; | ||
| Success: Success.Component; | ||
| Submit: Submit.Component; | ||
| Cancel: Cancel.Component; | ||
| Notice: Notice.Component; | ||
| }; | ||
| } | ||
|
|
||
| /** @deprecated It will be removed in v18. */ | ||
| export type FeedbackFormProps = NSFeedbackForm.Props; | ||
|
|
||
| export type { NSFeedbackForm }; |
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 |
|---|---|---|
| @@ -1,8 +1,7 @@ | ||
| import { Box, Flex } from '@semcore/base-components'; | ||
| import type Button from '@semcore/button'; | ||
| import type Checkbox from '@semcore/checkbox'; | ||
| import { createComponent, Component, sstyled, Root } from '@semcore/core'; | ||
| import type { Intergalactic } from '@semcore/core'; | ||
| import type { WithI18nEnhanceProps } from '@semcore/core/lib/utils/enhances/i18nEnhance'; | ||
| import i18nEnhance from '@semcore/core/lib/utils/enhances/i18nEnhance'; | ||
| import uniqueIDEnhancement from '@semcore/core/lib/utils/uniqueID'; | ||
| import CheckM from '@semcore/icon/Check/m'; | ||
|
|
@@ -20,38 +19,28 @@ import createFocusDecorator from 'final-form-focus'; | |
| import React, { type ReactElement } from 'react'; | ||
| import { Field, Form } from 'react-final-form'; | ||
|
|
||
| import type { | ||
| FeedbackRatingCheckboxProps, | ||
| FeedbackRatingItemProps, | ||
| FeedbackRatingProps, | ||
| FormConfigItem, | ||
| FeedbackRatingDefaultProps, | ||
| } from './FeedbackRating.type'; | ||
| import style from '../../style/feedback-rating.shadow.css'; | ||
| import { localizedMessages } from '../../translations/__intergalactic-dynamic-locales'; | ||
| import CheckboxButton from '../checkbox-button/CheckboxButton'; | ||
| import { FeedbackItem } from '../feedback-item/FeedbackItem'; | ||
| import SliderRating from '../slider-rating/SliderRating'; | ||
| import { SubmitButton } from '../submit-button/SubmitButton'; | ||
|
|
||
| type State = { | ||
| error: boolean; | ||
| }; | ||
| import CheckboxButton from './component/checkbox-button/CheckboxButton'; | ||
| import { FeedbackItem } from './component/feedback-item/FeedbackItem'; | ||
| import SliderRating from './component/slider-rating/SliderRating'; | ||
| import { SubmitButton } from './component/submit-button/SubmitButton'; | ||
| import type { NSFeedbackRating } from './FeedbackRating.type'; | ||
| import style from './style/feedback-rating.shadow.css'; | ||
| import { localizedMessages } from './translations/__intergalactic-dynamic-locales'; | ||
|
|
||
| class FeedbackRatingRoot extends Component< | ||
| FeedbackRatingProps, | ||
| Intergalactic.InternalTypings.InferComponentProps<NSFeedbackRating.Component>, | ||
| typeof FeedbackRatingRoot.enhance, | ||
| {}, | ||
| {}, | ||
| State, | ||
| FeedbackRatingDefaultProps | ||
| WithI18nEnhanceProps, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure about this...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's need to correctly type |
||
| NSFeedbackRating.State, | ||
| NSFeedbackRating.DefaultProps | ||
| > { | ||
| static displayName = 'FeedbackRatingForm'; | ||
| static style = style; | ||
|
|
||
| static enhance = [i18nEnhance(localizedMessages), uniqueIDEnhancement()] as const; | ||
|
|
||
| static defaultProps: FeedbackRatingDefaultProps = { | ||
| static defaultProps: NSFeedbackRating.DefaultProps = { | ||
| onSubmit: () => {}, | ||
| i18n: localizedMessages, | ||
| locale: 'en', | ||
|
|
@@ -74,7 +63,7 @@ class FeedbackRatingRoot extends Component< | |
| }, | ||
| }; | ||
|
|
||
| state: State = { | ||
| state: NSFeedbackRating.State = { | ||
| error: false, | ||
| }; | ||
|
|
||
|
|
@@ -122,7 +111,7 @@ class FeedbackRatingRoot extends Component< | |
| fn(e); | ||
| }; | ||
|
|
||
| componentDidUpdate(prevProps: Readonly<FeedbackRatingProps>) { | ||
| componentDidUpdate(prevProps: typeof this.asProps) { | ||
| const { status, getI18nText } = this.asProps; | ||
|
|
||
| if (prevProps.status !== status) { | ||
|
|
@@ -144,7 +133,7 @@ class FeedbackRatingRoot extends Component< | |
| } | ||
| } | ||
|
|
||
| renderCheckbox = (config: FormConfigItem, index: number) => { | ||
| renderCheckbox = (config: NSFeedbackRating.FormConfigItem, index: number) => { | ||
| const initialValue = this.props.initialValues[config.key]; | ||
|
|
||
| return ( | ||
|
|
@@ -154,15 +143,15 @@ class FeedbackRatingRoot extends Component< | |
| {...input} | ||
| id={config.key} | ||
| label={config.label} | ||
| onChange={(_checked, e) => input.onChange(e)} | ||
| onChange={(_: boolean, e?: React.SyntheticEvent<HTMLInputElement>) => input.onChange(e)} | ||
| focused={index === 0} | ||
| /> | ||
| )} | ||
| </Field> | ||
| ); | ||
| }; | ||
|
|
||
| renderTextField = (config: FormConfigItem) => { | ||
| renderTextField = (config: NSFeedbackRating.FormConfigItem) => { | ||
| const initialValue = this.props.initialValues[config.key]; | ||
|
|
||
| const label = | ||
|
|
@@ -369,8 +358,6 @@ class FeedbackRatingRoot extends Component< | |
| </SemcoreNotice.Label> | ||
| <SemcoreNotice.Content> | ||
| {getI18nText('errorMessage', { | ||
| // todo: Brauer Ilia - think how to fix type | ||
| // @ts-ignore | ||
| email: ( | ||
| <Link href={`mailto:${errorFeedbackEmail}`}> | ||
| {errorFeedbackEmail} | ||
|
|
@@ -401,29 +388,23 @@ class FeedbackRatingRoot extends Component< | |
| } | ||
| } | ||
|
|
||
| function Header(props: any) { | ||
| function Header( | ||
| props: Intergalactic.InternalTypings.InferChildComponentProps<NSFeedbackRating.Header.Component, typeof FeedbackRatingRoot, 'Header'>, | ||
| ) { | ||
| const { styles } = props; | ||
| const SHeader = Root; | ||
| return sstyled(styles)( | ||
| <SHeader render={Modal.Title} />, | ||
| ); | ||
| } | ||
|
|
||
| type FeedbackRatingComponent = Intergalactic.Component<'form', FeedbackRatingProps, {}, typeof FeedbackRatingRoot.enhance> & { | ||
| validate: typeof FeedbackRatingRoot.validate; | ||
| Item: Intergalactic.Component<'div', FeedbackRatingItemProps>; | ||
| Submit: typeof Button; | ||
| Checkbox: Intergalactic.Component<typeof Checkbox, FeedbackRatingCheckboxProps>; | ||
| Header: typeof Text; | ||
| }; | ||
|
|
||
| /** | ||
| * FeedbackRating | ||
| * | ||
| * {@link https://developer.semrush.com/intergalactic/components/feedback-form/feedback-form-api#feedbackform-feedbackrating|API} | {@link https://developer.semrush.com/intergalactic/components/feedback-form/feedback-form-code/|Examples} | ||
| */ | ||
| const FeedbackRating = createComponent< | ||
| FeedbackRatingComponent, | ||
| NSFeedbackRating.Component, | ||
| typeof FeedbackRatingRoot | ||
| >(FeedbackRatingRoot, { | ||
| Header, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.