-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add editor mode switch #404
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d58796c
feat: add editor view switch pt.1
gorgeousvlad 0e3013d
fix: form scroll bug
gorgeousvlad eb3cb85
feat: add editor layout
gorgeousvlad 1a92d49
fix: move editor styles to layout
gorgeousvlad 403fedd
fix: form spy double change callback calling fix
gorgeousvlad 607dcc3
fix: light theme for control panel
gorgeousvlad 65e80ad
fix: preview mode header slider
gorgeousvlad 45027fe
fix: review
gorgeousvlad 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| @import '../../../../styles/variables.scss'; | ||
| @import '../../../../styles/mixins.scss'; | ||
| @import '../../styles/mixins.scss'; | ||
| @import '../../styles/variables.scss'; | ||
|
|
||
| $block: '.#{$ns}control-panel'; | ||
|
|
||
| #{$block} { | ||
| display: flex; | ||
| justify-content: center; | ||
| width: 100%; | ||
| height: var(--editor-header-height); | ||
| padding: $indentXXXS $indentS; | ||
| background-color: var(--yc-color-base-background); | ||
| border-bottom: 1px solid var(--yc-color-line-generic); | ||
|
|
||
| &__icon { | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
|
|
||
| &__radio-button { | ||
| margin-left: $indentXXS; | ||
| //align for icons in radio buttons | ||
| .yc-radio-button__option { | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
| } | ||
|
|
||
| &__mode-switch { | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
| } |
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,55 @@ | ||
| import React from 'react'; | ||
|
|
||
| import {Display, Pencil} from '@gravity-ui/icons'; | ||
| import {RadioButton} from '@gravity-ui/uikit'; | ||
|
|
||
| import {ClassNameProps} from '../../../models'; | ||
| import {block} from '../../../utils'; | ||
| import {ViewModeItem} from '../../types'; | ||
|
|
||
| import i18n from './i18n'; | ||
|
|
||
| const ICON_SIZE = 14; | ||
|
|
||
| import './ControlPanel.scss'; | ||
|
|
||
| const b = block('control-panel'); | ||
|
|
||
| const ControlPanelViewModeIcons = { | ||
| [ViewModeItem.Edititng]: Pencil, | ||
| [ViewModeItem.View]: Display, | ||
| }; | ||
|
|
||
| export interface ControlPanelProps extends ClassNameProps { | ||
| viewMode?: ViewModeItem; | ||
| onViewModeChange: (viewMode: ViewModeItem) => void; | ||
| } | ||
|
|
||
| const ControlPanel = ({ | ||
| viewMode = ViewModeItem.Edititng, | ||
| onViewModeChange, | ||
| className, | ||
| }: ControlPanelProps) => ( | ||
| <div className={b(null, className)}> | ||
| <div className={b('mode-switch')}> | ||
| <span>{i18n('mode')}</span> | ||
| <RadioButton | ||
| className={b('radio-button')} | ||
| value={viewMode} | ||
| onUpdate={(value) => onViewModeChange(value as ViewModeItem)} | ||
| > | ||
| {Object.values(ViewModeItem).map((item) => { | ||
| const Icon = ControlPanelViewModeIcons[item]; | ||
|
|
||
| return ( | ||
| <RadioButton.Option key={item} value={item}> | ||
| <Icon className={b('icon')} width={ICON_SIZE} height={ICON_SIZE} /> | ||
| </RadioButton.Option> | ||
| ); | ||
| })} | ||
| </RadioButton> | ||
| </div> | ||
| </div> | ||
| ); | ||
|
|
||
| export default ControlPanel; |
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,3 @@ | ||
| { | ||
| "mode": "Mode" | ||
| } |
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,8 @@ | ||
| import {registerKeyset} from '../../../../utils/registerKeyset'; | ||
|
|
||
| import en from './en.json'; | ||
| import ru from './ru.json'; | ||
|
|
||
| const COMPONENT = 'ControlPanel'; | ||
|
|
||
| export default registerKeyset({en, ru}, COMPONENT); |
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,3 @@ | ||
| { | ||
| "mode": "Режим" | ||
| } |
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,44 @@ | ||
| @import '../../../../styles/variables.scss'; | ||
| @import '../../../../styles/mixins.scss'; | ||
| @import '../../styles/root.scss'; | ||
| @import '../../styles/variables.scss'; | ||
| @import '../../styles/mixins.scss'; | ||
|
|
||
| $block: '.#{$ns}editor-layout'; | ||
|
|
||
| %overflow-container { | ||
| --yc-scrollbar-width: 0; | ||
| height: calc(100vh - var(--editor-header-height)); | ||
| max-height: calc(100vh - var(--editor-header-height)); | ||
| overflow-y: auto; | ||
| } | ||
|
|
||
| #{$block} { | ||
| position: relative; | ||
|
|
||
| &__panel { | ||
| top: 0; | ||
| position: sticky; | ||
| z-index: 2; | ||
| } | ||
|
|
||
| &__container { | ||
| position: relative; | ||
| display: flex; | ||
| justify-content: center; | ||
| z-index: 1; | ||
| } | ||
|
|
||
| &__left, | ||
| &__right { | ||
| @extend %overflow-container; | ||
| } | ||
|
|
||
| &__left { | ||
| flex: 0 0 auto; | ||
| padding: $indentXXXS $indentS $indentS; | ||
| width: var(--editor-left-column-width); | ||
| border-right: var(--editor-divider-width) solid var(--yc-color-line-generic); | ||
| overflow-x: auto; | ||
| } | ||
| } |
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,53 @@ | ||
| import React, {Children, Fragment, PropsWithChildren, ReactElement} from 'react'; | ||
|
|
||
| import {block} from '../../../utils'; | ||
| import {ViewModeItem} from '../../types'; | ||
| import ControlPanel from '../ControlPanel/ControlPanel'; | ||
|
|
||
| import './Layout.scss'; | ||
|
|
||
| const b = block('editor-layout'); | ||
|
|
||
| const Left: React.FC<PropsWithChildren> = () => null; | ||
| const Right: React.FC<PropsWithChildren> = () => null; | ||
|
|
||
| export interface LayoutProps { | ||
| mode: ViewModeItem; | ||
| onModeChange: (mode: ViewModeItem) => void; | ||
| } | ||
|
|
||
| const Layout = ({children, mode, onModeChange}: PropsWithChildren<LayoutProps>) => { | ||
| let left, right; | ||
|
|
||
| function handleChild(child: ReactElement) { | ||
| switch (child?.type) { | ||
| case Left: | ||
| left = child?.props.children; | ||
| break; | ||
| case Right: | ||
| right = child?.props.children; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (React.Children.toArray(children).length) { | ||
| Children.forEach(children as ReactElement, handleChild); | ||
| } | ||
|
|
||
| return ( | ||
| <div className={b()}> | ||
| <ControlPanel viewMode={mode} onViewModeChange={onModeChange} className={b('panel')} /> | ||
| <div className={b('container')}> | ||
| <Fragment> | ||
| {left && <div className={b('left')}>{left}</div>} | ||
| {right && <div className={b('right')}>{right}</div>} | ||
| </Fragment> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| Layout.Left = Left; | ||
| Layout.Right = Right; | ||
|
|
||
| export default Layout; | ||
This file was deleted.
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.