-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from bridgedxyz/designer/icon
0.1.4 release - added icons loader, icon detection, icon button detection, illust detection, and more
- Loading branch information
Showing
20 changed files
with
296 additions
and
85 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"git.ignoreLimitWarning": true | ||
} |
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
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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
|
||
code{ | ||
code { | ||
width: max-content; | ||
height: auto; | ||
} | ||
|
||
|
||
pre { | ||
margin-left:-16px; | ||
margin-left: -16px; | ||
margin-right: -16px; | ||
padding: 8px; | ||
overflow: scroll; | ||
} | ||
|
||
.copy{ | ||
.sticky-actions { | ||
position: sticky; | ||
right: 4px; | ||
margin-right: 16px; | ||
top: 4px; | ||
} |
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,142 @@ | ||
import React, { useEffect, useState } from "react" | ||
import { IconConfig } from "@bridged.xyz/client-sdk/lib" | ||
import Tooltip from "@material-ui/core/Tooltip"; | ||
import IconButton from "@material-ui/core/IconButton"; | ||
import GridList from "@material-ui/core/GridList"; | ||
import GridListTile from "@material-ui/core/GridListTile"; | ||
import { EK_CREATE_ICON } from "../constants/ek.constant"; | ||
import { loadSvg, makeIconUrl } from "../../assets-repository/icons-generator"; | ||
import TextField from "@material-ui/core/TextField"; | ||
import LinearProgress from "@material-ui/core/LinearProgress"; | ||
const CONFIG_JSON_S3 = "https://reflect-icons.s3-us-west-1.amazonaws.com/material/config.json" | ||
|
||
|
||
// cached icons configs | ||
let CONFIGS: Map<string, IconConfig> | ||
export function IconsLoader() { | ||
const [configs, setConfigs] = useState<Map<string, IconConfig>>(undefined); | ||
const [queryTerm, setQueryTerm] = useState<string>(undefined); | ||
|
||
useEffect(() => { | ||
if (CONFIGS) { | ||
setConfigs(CONFIGS) | ||
} else { | ||
fetch(CONFIG_JSON_S3) | ||
.then((response) => response.json()) | ||
.then((json) => { | ||
CONFIGS = json | ||
setConfigs(json) | ||
}) | ||
} | ||
}, []); | ||
|
||
|
||
let list; | ||
if (configs) { | ||
const MAX_PER_LOAD = 100 | ||
const validQueryTerm = queryTerm !== undefined && queryTerm.length >= 2 | ||
const searchOnlyDefaults: boolean = !validQueryTerm | ||
const defaultIcons = filterIcons(configs, { | ||
onlyDefault: searchOnlyDefaults, | ||
includes: validQueryTerm ? queryTerm : undefined | ||
}).slice(0, MAX_PER_LOAD) | ||
list = <IconList icons={defaultIcons} /> | ||
} else { | ||
list = <LinearProgress /> | ||
} | ||
|
||
return ( | ||
<> | ||
<IconSearch onChange={setQueryTerm} /> | ||
{list} | ||
</> | ||
) | ||
} | ||
|
||
function IconSearch(props: { | ||
onChange: (value: string) => void | ||
}) { | ||
return ( | ||
<TextField id="standard-basic" label="search with icon name" onChange={(e) => props.onChange(e.target.value)} /> | ||
) | ||
} | ||
|
||
function filterIcons(configs: Map<string, IconConfig>, options: { | ||
onlyDefault: boolean, | ||
includes?: string | ||
}): [string, IconConfig][] { | ||
const keys = Object.keys(configs) | ||
const defaultIcons = keys.map<[string, IconConfig]>((k) => { | ||
const item = configs[k] as IconConfig | ||
if (options.onlyDefault) { | ||
if (item.variant != 'default') { | ||
return undefined | ||
} | ||
} | ||
|
||
if (options.includes) { | ||
if (k.includes(options.includes)) { | ||
return [k, item] | ||
} else { | ||
return | ||
} | ||
} | ||
return [k, item] | ||
|
||
}).filter((k) => k !== undefined) | ||
console.log('default icons', defaultIcons.length) | ||
return defaultIcons | ||
} | ||
|
||
function IconList(props: { | ||
icons: [string, IconConfig][] | ||
}) { | ||
const { icons } = props | ||
|
||
return <> | ||
<GridList cellHeight={160} cols={5}> | ||
{ | ||
icons.map((i) => { | ||
const key = i[0] | ||
const config = i[1] | ||
return <GridListTile key={key}> | ||
<IconItem key={key} name={key} config={config} /> | ||
</GridListTile> | ||
}) | ||
} | ||
</GridList> | ||
</> | ||
} | ||
|
||
function IconItem(props: { | ||
name: string, | ||
config: IconConfig | ||
}) { | ||
const { name, config } = props | ||
|
||
const onClick = () => { | ||
console.log(name, 'clicked') | ||
loadSvg(name, config).then((s) => { | ||
console.log('postmessage', EK_CREATE_ICON) | ||
parent.postMessage({ | ||
pluginMessage: { | ||
type: EK_CREATE_ICON, | ||
data: { | ||
key: name, | ||
svg: s | ||
} | ||
} | ||
}, "*") | ||
}) | ||
} | ||
|
||
return <div> | ||
<Tooltip title={`${name} (${config.variant})`}> | ||
<IconButton aria-label="delete" onClick={onClick}> | ||
<svg width="24" height="24"> | ||
<image xlinkHref={makeIconUrl(name, config)} width="24" height="24" /> | ||
</svg> | ||
</IconButton> | ||
</Tooltip> | ||
</div> | ||
} |
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
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,5 @@ | ||
import React from "react" | ||
import { IconsLoader } from "../components/icons-loader" | ||
export function IconsScreen() { | ||
return <IconsLoader /> | ||
} |
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 |
---|---|---|
@@ -1,5 +1,41 @@ | ||
import { IconConfig } from "@bridged.xyz/client-sdk/lib" | ||
import Axios from "axios" | ||
export function insertMaterialIcon(name: string, data: string): FrameNode { | ||
console.log(`inserting icon with name ${name} and data ${data}`) | ||
|
||
export function insertMaterialIcon(name: string): FrameNode { | ||
const svg = "" // todo load via name | ||
return figma.createNodeFromSvg(svg) | ||
const currentViewportLocation = figma.viewport.center | ||
const node = figma.createNodeFromSvg(data) | ||
// todo replace naming creation with reflect core | ||
node.name = `icons/mdi_${name}` | ||
node.setSharedPluginData('icon', 'key', name) | ||
node.x = currentViewportLocation.x | ||
node.y = currentViewportLocation.y | ||
return node | ||
} | ||
|
||
|
||
export async function loadSvg(key: string, config: IconConfig): Promise<string> { | ||
// let header = new Headers({ | ||
// 'Access-Control-Allow-Origin':'*', | ||
// 'Content-Type': 'multipart/form-data' | ||
// }); | ||
// let sentData={ | ||
// method:'GET', | ||
// mode: 'cors', | ||
// header: header, | ||
// }; | ||
|
||
const url = makeIconUrl(key, config) | ||
const raw = await (await Axios.get(url, { | ||
headers: { | ||
'Access-Control-Allow-Origin': '*', | ||
} | ||
})).data | ||
// const raw = await (await fetch(, sentData)).text() | ||
console.log(`icon raw data loaded for ${key}, length of ${raw.length}`) | ||
return raw | ||
} | ||
|
||
export function makeIconUrl(name: string, config: IconConfig): string { | ||
return `https://reflect-icons.s3-us-west-1.amazonaws.com/${config.host}/${name}.svg` | ||
} |
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
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
Oops, something went wrong.