Skip to content

Commit 6de48fc

Browse files
PierreCrbbaptadn
andauthored
feat: add Highlight component
* add high light component * add tabs * remove log * improve highlight support Co-authored-by: shinework <[email protected]>
1 parent 466dcde commit 6de48fc

File tree

13 files changed

+96
-38
lines changed

13 files changed

+96
-38
lines changed

src/components/editor/ComponentPreview.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const componentsToTest = [
5151
'Textarea',
5252
'CircularProgress',
5353
'Heading',
54+
'Highlight',
5455
'Tag',
5556
'Switch',
5657
'FormLabel',

src/components/editor/ComponentPreview.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import SelectPreview from '~components/editor/previews/SelectPreview'
2525
import NumberInputPreview from '~components/editor/previews/NumberInputPreview'
2626
import BreadcrumbPreview from './previews/BreadcrumbPreview'
2727
import BreadcrumbItemPreview from './previews/BreadcrumbItemPreview'
28+
import HighlightPreview from './previews/HighlightPreview'
2829

2930
const ComponentPreview: React.FC<{
3031
componentName: string
@@ -154,6 +155,9 @@ const ComponentPreview: React.FC<{
154155
return <SelectPreview component={component} />
155156
case 'NumberInput':
156157
return <NumberInputPreview component={component} />
158+
case 'Highlight':
159+
return <HighlightPreview component={component} />
160+
157161
default:
158162
return null
159163
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react'
2+
import { useInteractive } from '~hooks/useInteractive'
3+
import { Box, Highlight } from '@chakra-ui/react'
4+
5+
const HighlightPreview: React.FC<IPreviewProps> = ({ component }) => {
6+
const { props, ref } = useInteractive(component, true, true)
7+
8+
return (
9+
<Box {...props} ref={ref}>
10+
<Highlight {...component.props} styles={component.props} />
11+
</Box>
12+
)
13+
}
14+
15+
export default HighlightPreview

src/components/inspector/panels/Panels.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import NumberInputPanel from '~components/inspector/panels/components/NumberInpu
4848
import AspectRatioPanel from '~components/inspector/panels/components/AspectRatioPanel'
4949
import BreadcrumbPanel from '~components/inspector/panels/components/BreadcrumbPanel'
5050
import BreadcrumbItemPanel from '~components/inspector/panels/components/BreadcrumbItemPanel'
51+
import HighlightPanel from '~components/inspector/panels/components/HighlightPanel'
5152

5253
const Panels: React.FC<{ component: IComponent; isRoot: boolean }> = ({
5354
component,
@@ -81,6 +82,7 @@ const Panels: React.FC<{ component: IComponent; isRoot: boolean }> = ({
8182
{type === 'Textarea' && <TextareaPanel />}
8283
{type === 'CircularProgress' && <CircularProgressPanel />}
8384
{type === 'Heading' && <HeadingPanel />}
85+
{type === 'Highlight' && <HighlightPanel />}
8486
{type === 'SimpleGrid' && <SimpleGridPanel />}
8587
{type === 'Switch' && <SwitchPanel />}
8688
{type === 'Alert' && <AlertPanel />}

src/components/inspector/panels/StylesPanel.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { memo } from 'react'
22
import { Accordion } from '@chakra-ui/react'
3-
43
import PaddingPanel from '~components/inspector/panels/styles/PaddingPanel'
54
import DimensionPanel from '~components/inspector/panels/styles/DimensionPanel'
65
import BorderPanel from '~components/inspector/panels/styles/BorderPanel'
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import React from 'react'
22
import ChildrenControl from '~components/inspector/controls/ChildrenControl'
33

4-
const FormErrorMessagePanel = () => {
5-
return (
6-
<>
7-
<ChildrenControl />
8-
</>
9-
)
10-
}
4+
const FormErrorMessagePanel = () => <ChildrenControl />
115

126
export default FormErrorMessagePanel
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { memo } from 'react'
2+
import ChildrenControl from '~components/inspector/controls/ChildrenControl'
3+
import TextControl from '~components/inspector/controls/TextControl'
4+
5+
const HighlightPanel = () => (
6+
<>
7+
<ChildrenControl />
8+
<TextControl label="Query" name="query" />
9+
</>
10+
)
11+
12+
export default memo(HighlightPanel)

src/componentsList.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const menuItems: MenuItems = {
6363
},
6464
Grid: {},
6565
Heading: {},
66+
Highlight: {},
6667
Icon: {},
6768
IconButton: {},
6869
Image: {},
@@ -141,6 +142,7 @@ export const componentsList: ComponentType[] = [
141142
'FormLabel',
142143
'Grid',
143144
'Heading',
145+
'Highlight',
144146
'Icon',
145147
'IconButton',
146148
'Image',

src/hooks/useInteractive.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { getShowLayout, getFocusedComponent } from '../core/selectors/app'
1010

1111
export const useInteractive = (
1212
component: IComponent,
13-
enableVisualHelper: boolean = false,
13+
enableVisualHelper = false,
14+
withoutComponentProps = false,
1415
) => {
1516
const dispatch = useDispatch()
1617
const showLayout = useSelector(getShowLayout)
@@ -24,7 +25,7 @@ export const useInteractive = (
2425

2526
const ref = useRef<HTMLDivElement>(null)
2627
let props = {
27-
...component.props,
28+
...(withoutComponentProps ? {} : component.props),
2829
onMouseOver: (event: MouseEvent) => {
2930
event.stopPropagation()
3031
dispatch.components.hover(component.id)

src/react-app-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type ComponentType =
3838
| 'FormErrorMessage'
3939
| 'Grid'
4040
| 'Heading'
41+
| 'Highlight'
4142
| 'Icon'
4243
| 'IconButton'
4344
| 'Image'

0 commit comments

Comments
 (0)