1- import React , { useRef } from "react" ;
1+ import React from "react" ;
22import styled from "@emotion/styled" ;
3- import type { ReflectSceneNode } from "@design-sdk/figma-node" ;
4- import { FigmaNodeBitmapView } from "@code-editor/canvas-renderer-bitmap" ;
5- import { SceneNodeIcon } from "@code-editor/node-icons" ;
63import Highlighter from "react-highlight-words" ;
7- import { useInViewport } from "react-in-viewport" ;
8- import { mergeRefs } from "react-merge-refs" ;
94
10- export interface SceneCardProps {
11- scene : ReflectSceneNode ;
5+ export interface DashboardItemCardProps {
126 selected ?: boolean ;
137 onClick ?: ( e ) => void ;
148 onDoubleClick ?: ( ) => void ;
@@ -18,31 +12,28 @@ export interface SceneCardProps {
1812 * an explicit field to set the view as accepting drag state view.
1913 */
2014 isOver ?: boolean ;
15+ preview : React . ReactNode ;
16+ label : string ;
17+ icon ?: React . ReactNode ;
2118}
2219
23- export const SceneCard = React . forwardRef ( function (
20+ export const DashboardItemCard = React . forwardRef ( function (
2421 {
25- style = { } ,
26- scene,
27- selected,
2822 onClick,
2923 onDoubleClick,
30- q ,
24+ selected ,
3125 isOver,
32- } : SceneCardProps ,
33- ref
26+ style = { } ,
27+ label,
28+ q,
29+ icon,
30+ preview,
31+ } : DashboardItemCardProps ,
32+ ref : React . Ref < HTMLDivElement >
3433) {
35- const visibilityRef = useRef ( ) ;
36- const { enterCount } = useInViewport ( visibilityRef ) ;
37-
38- const maxwidth = 300 ;
39-
40- // max allowed zoom = 1
41- const scale = Math . min ( maxwidth / scene . width , 1 ) ;
42- const { height, type } = scene ;
4334 return (
4435 < Card
45- ref = { mergeRefs ( [ visibilityRef , ref ] ) }
36+ ref = { ref }
4637 onClick = { onClick }
4738 onDoubleClick = { onDoubleClick }
4839 data-selected = { selected }
@@ -51,43 +42,18 @@ export const SceneCard = React.forwardRef(function (
5142 ...style ,
5243 } }
5344 >
54- { /* sizer */ }
55- < Preview
56- data-selected = { selected }
57- data-over = { isOver }
58- style = { {
59- height : height * scale ,
60- width : maxwidth ,
61- } }
62- >
45+ < PreviewContainer data-selected = { selected } data-over = { isOver } >
6346 < span id = "overlay" />
64- { /* transformer */ }
65- < div
66- id = "view"
67- style = { {
68- transform : `scale(${ scale } )` ,
69- } }
70- >
71- < FigmaNodeBitmapView
72- background = { "white" }
73- key = { scene . id }
74- target = { scene }
75- isPanning = { false }
76- isZooming = { false }
77- zoom = { null }
78- inViewport = { enterCount > 0 }
79- focused = { false }
80- />
81- </ div >
82- </ Preview >
47+ { preview }
48+ </ PreviewContainer >
8349 < footer >
8450 < label >
85- < SceneNodeIcon type = { type } color = "white" />
51+ { ! ! icon && icon }
8652 < Highlighter
8753 className = "name"
8854 highlightClassName = "name"
8955 searchWords = { q ? [ q ] : [ ] }
90- textToHighlight = { scene . name }
56+ textToHighlight = { label }
9157 autoEscape // required to escape regex special characters, like, `+`, `(`, `)`, etc.
9258 />
9359 </ label >
@@ -131,7 +97,7 @@ const Card = styled.div`
13197 }
13298` ;
13399
134- const Preview = styled . div `
100+ const PreviewContainer = styled . div `
135101 outline: 1px solid rgba(0, 0, 0, 0.1);
136102 border-radius: 2px;
137103 overflow: hidden;
0 commit comments