-
Notifications
You must be signed in to change notification settings - Fork 14
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: add blocks/Form #659
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c2277ee
feat: add blocks/Form
qradle-yndx 89569b3
fix: fix storybook YandexForm import
qradle-yndx cbd2260
fix: add form block review fixes
qradle-yndx 413bfd1
fix: form block inner fix useEffect onContentLoad deps
qradle-yndx 89929b5
fix: distinguish yandex form surveys path url as param with cloud def…
qradle-yndx f34f35d
feat: add hubspot form to form-block storybook cases. merge backgroun…
qradle-yndx b231466
fix: change yandex form default customFormSection to surveys
qradle-yndx b13903a
fix: add yaFormSection to useCallback deps
qradle-yndx b8e6ddb
style: fix form-block one-line if
qradle-yndx 01af139
style: rename form-block storybook content form direction case
qradle-yndx 5bf51b0
fix: fix react-spring version
qradle-yndx b93ae71
fix: change versions
qradle-yndx 5be4f00
fix: lock file
qradle-yndx 46ca362
4.29.1-alpha.0
gravity-ui-bot 978e0bc
fix: change versions
qradle-yndx d5a6ad9
4.31.1-alpha.0
gravity-ui-bot d338f1c
fix: fix version and Form block formType useMemo removed
qradle-yndx a020bea
fix: cut HubspotInlineForm, add title to form storybook
qradle-yndx 2e83c72
fix: use default theme for form-block storybook
qradle-yndx 7a22755
fix: add createDOMElement to form-block HubspotForm
qradle-yndx f274388
fix: rename hubspot-inline to hubspot
qradle-yndx 42b303d
fix: rename hubspot-inline to hubspot
qradle-yndx 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 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,228 @@ | ||
@import '../../../styles/mixins.scss'; | ||
@import '../../../styles/variables.scss'; | ||
|
||
$block: '.#{$ns}form-block'; | ||
|
||
$textPadding: 10px; | ||
$maxLargeWidth: 609px; | ||
$yandexFormDesktopMinWidth: 475px; | ||
$largeBorderRadius: 32px; | ||
|
||
#{$block} { | ||
$root: &; | ||
|
||
border-radius: $largeBorderRadius; | ||
position: relative; | ||
|
||
&__title { | ||
margin: 0 0 $indentSM $textPadding; | ||
|
||
&_mobile { | ||
margin-left: 4px; | ||
} | ||
} | ||
|
||
&__full-form { | ||
background-color: var(--g-color-base-background); | ||
padding: $indentL $indentXL $indentL calc(#{$indentXL} - #{$textPadding}); | ||
border-radius: $borderRadius; | ||
} | ||
|
||
&__media { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
bottom: 0; | ||
right: 0; | ||
border-radius: $largeBorderRadius; | ||
} | ||
|
||
&__image { | ||
height: 100%; | ||
width: 100%; | ||
object-fit: cover; | ||
} | ||
|
||
&__row { | ||
&_direction { | ||
&_form-content { | ||
flex-direction: row-reverse; | ||
} | ||
|
||
&_center { | ||
padding-top: $indentXL; | ||
padding-bottom: $indentL; | ||
flex-direction: column; | ||
|
||
#{$root}__content-wrapper { | ||
margin-bottom: $indentM; | ||
} | ||
} | ||
} | ||
} | ||
|
||
&:not(#{$root}_with-background) { | ||
#{$root}__full-form { | ||
box-shadow: 0 4px 24px var(--pc-color-sfx-shadow), 0 2px 8px var(--pc-color-sfx-shadow); | ||
} | ||
#{$root}__row { | ||
&_direction { | ||
&_form-content { | ||
#{$root}__content-wrapper { | ||
padding: $indentL 0 $indentXL $indentXL; | ||
} | ||
} | ||
&_content-form { | ||
#{$root}__content-wrapper { | ||
padding: $indentL $indentXL $indentXL 0; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
&_with-background { | ||
#{$root}__row { | ||
&_direction { | ||
&_form-content { | ||
#{$root}__form-wrapper { | ||
padding: $indentXS 0 $indentSM $indentXS; | ||
} | ||
} | ||
&_content-form { | ||
#{$root}__form-wrapper { | ||
padding: $indentXS $indentXS $indentSM 0; | ||
} | ||
} | ||
&_form-content, | ||
&_content-form { | ||
#{$root}__content-wrapper { | ||
padding: $indentXL; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@media (min-width: map-get($gridBreakpoints, 'lg')) { | ||
&_form-type_yandex { | ||
#{$root}__row { | ||
&_direction { | ||
&_form-content, | ||
&_content-form { | ||
#{$root}__content-col { | ||
flex: 1 0 0; | ||
} | ||
} | ||
|
||
&_form-content, | ||
&_content-form, | ||
&_center { | ||
#{$root}__form { | ||
min-width: $yandexFormDesktopMinWidth; | ||
} | ||
#{$root}__form-col { | ||
max-width: initial; | ||
width: fit-content; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@media (max-width: map-get($gridBreakpoints, 'lg')) and (min-width: map-get($gridBreakpoints, 'md')) { | ||
&__row { | ||
flex-direction: column; | ||
} | ||
|
||
&_with-background, | ||
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. does both this classes mean that there is styles need to be applied unconditionally? 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. this classes does make sense inside media queries |
||
&:not(#{$root}_with-background) { | ||
#{$root}__row { | ||
#{$root}__form-wrapper, | ||
#{$root}__content-wrapper { | ||
max-width: $maxLargeWidth; | ||
} | ||
|
||
#{$root}__center, | ||
#{$root}__form-wrapper, | ||
#{$root}__content-wrapper { | ||
margin: 0 auto; | ||
padding-right: 0; | ||
padding-left: 0; | ||
} | ||
|
||
#{$root}__form-wrapper { | ||
padding-top: 0; | ||
} | ||
|
||
#{$root}__content-wrapper { | ||
text-align: center; | ||
padding-bottom: $indentM; | ||
} | ||
} | ||
} | ||
|
||
&:not(#{$root}_with-background) &__row { | ||
#{$root}__content-wrapper { | ||
padding: 0 0 $indentM 0; | ||
} | ||
} | ||
} | ||
|
||
@media (max-width: map-get($gridBreakpoints, 'md')) { | ||
&__full-form { | ||
padding: $indentM; | ||
} | ||
|
||
&_with-background, | ||
&:not(#{$root}_with-background) { | ||
#{$root}__row { | ||
padding: 0; | ||
|
||
#{$root}__form-wrapper, | ||
#{$root}__content-wrapper { | ||
padding: 0; | ||
} | ||
|
||
#{$root}__content-wrapper { | ||
padding-bottom: $indentM; | ||
margin-bottom: 0; | ||
} | ||
} | ||
} | ||
|
||
&_with-background { | ||
padding: 0 $indentXXXS; | ||
|
||
#{$root}__row { | ||
padding-top: $indentL; | ||
|
||
&_padding-bottom { | ||
&_m { | ||
padding-bottom: $indentM; | ||
} | ||
&_l { | ||
padding-bottom: $indentL; | ||
} | ||
} | ||
|
||
&_direction { | ||
&_form-content, | ||
&_content-form, | ||
&_center { | ||
#{$root}__content-wrapper { | ||
padding-right: $indentXS; | ||
padding-left: $indentXS; | ||
} | ||
} | ||
|
||
&_form-content, | ||
&_content-form { | ||
padding-top: $indentM; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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,117 @@ | ||
import React, {useCallback, useContext, useState} from 'react'; | ||
|
||
import {BackgroundImage, Title} from '../../components'; | ||
import {MobileContext} from '../../context/mobileContext'; | ||
import {Col, Grid, GridAlignItems, GridColumnSize, Row} from '../../grid'; | ||
import type {FormBlockProps} from '../../models'; | ||
import { | ||
FormBlockDataTypes, | ||
FormBlockDirection, | ||
isHubspotDataForm, | ||
isYandexDataForm, | ||
} from '../../models'; | ||
import {Content} from '../../sub-blocks'; | ||
import {block} from '../../utils'; | ||
|
||
import InnerForm from './InnerForm/InnerForm'; | ||
|
||
import './Form.scss'; | ||
|
||
const b = block('form-block'); | ||
|
||
const colSizes = {[GridColumnSize.Lg]: 6, [GridColumnSize.All]: 12}; | ||
|
||
const FormBlock: React.FC<FormBlockProps> = (props) => { | ||
const {formData, title, textContent, direction = FormBlockDirection.Center, background} = props; | ||
const [contentLoaded, setContentLoaded] = useState(false); | ||
const isMobile = useContext(MobileContext); | ||
|
||
const hasImage = background && (background.src || background.desktop); | ||
const paddingBottom = background && background.style?.backgroundColor && !hasImage ? 'l' : 'm'; // bigger padding for case with background color and no image | ||
const onContentLoad = useCallback(() => { | ||
setContentLoaded(true); | ||
}, []); | ||
|
||
if (!formData) { | ||
return null; | ||
} | ||
|
||
let formType; | ||
|
||
if (isYandexDataForm(formData)) { | ||
formType = FormBlockDataTypes.YANDEX; | ||
} else if (isHubspotDataForm(formData)) { | ||
formType = FormBlockDataTypes.HUBSPOT; | ||
} | ||
|
||
return ( | ||
<div | ||
className={b({ | ||
'with-background': Boolean(background), | ||
'form-type': formType, | ||
})} | ||
> | ||
{background && ( | ||
<BackgroundImage | ||
{...background} | ||
className={b('media')} | ||
imageClassName={b('image')} | ||
/> | ||
)} | ||
<Grid> | ||
<Row | ||
alignItems={ | ||
direction === FormBlockDirection.Center | ||
? GridAlignItems.Center | ||
: GridAlignItems.Start | ||
} | ||
className={b('row', { | ||
direction, | ||
'padding-bottom': paddingBottom, | ||
})} | ||
> | ||
<Col sizes={colSizes} className={b('content-col')}> | ||
{textContent && ( | ||
<div className={b('content-wrapper')}> | ||
<Content | ||
theme="default" | ||
{...textContent} | ||
centered={direction === FormBlockDirection.Center} | ||
colSizes={{all: 12}} | ||
className={b('content')} | ||
/> | ||
</div> | ||
)} | ||
</Col> | ||
<Col sizes={colSizes} className={b('form-col')}> | ||
<div className={b('form-wrapper')}> | ||
<div | ||
className={b('full-form', { | ||
hidden: !contentLoaded, | ||
})} | ||
> | ||
{title && ( | ||
<Title | ||
title={{ | ||
text: title, | ||
textSize: 's', | ||
}} | ||
className={b('title', {mobile: isMobile})} | ||
colSizes={{all: 12}} | ||
/> | ||
)} | ||
<InnerForm | ||
className={b('form')} | ||
formData={formData} | ||
onContentLoad={onContentLoad} | ||
/> | ||
</div> | ||
</div> | ||
</Col> | ||
</Row> | ||
</Grid> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FormBlock; |
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,44 @@ | ||
import React, {useEffect} from 'react'; | ||
|
||
import {YandexForm} from '../../../components'; | ||
import {FormBlockData, isHubspotDataForm, isYandexDataForm} from '../../../models'; | ||
import {HubspotForm} from '../../../sub-blocks'; | ||
|
||
interface InnerFormProps { | ||
formData: FormBlockData; | ||
onContentLoad: () => void; | ||
className?: string; | ||
} | ||
|
||
const InnerForm: React.FC<InnerFormProps> = (props) => { | ||
const {formData, onContentLoad, className} = props; | ||
|
||
useEffect(() => { | ||
if (isHubspotDataForm(formData)) { | ||
onContentLoad(); | ||
} | ||
}, [onContentLoad, formData]); | ||
|
||
if (isYandexDataForm(formData)) { | ||
const {onLoad, ...rest} = formData.yandex; | ||
return ( | ||
<div className={className}> | ||
<YandexForm | ||
{...rest} | ||
onLoad={() => { | ||
onContentLoad(); | ||
onLoad?.(); | ||
}} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
if (isHubspotDataForm(formData)) { | ||
return <HubspotForm createDOMElement={true} {...formData.hubspot} />; | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
export default InnerForm; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to use padding form standard set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean using $indentXXXS (8px) or $indentXXS (12px) from variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is indent from yandex/hubspot form