-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Destefanis
committed
May 4, 2023
1 parent
86cdcfd
commit 49e746b
Showing
10 changed files
with
405 additions
and
79 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React, { useState } from "react"; | ||
import StyleContent from "./StyleContent"; | ||
|
||
function ListItem({ style, index }) { | ||
// Use state to keep track of whether the list item is open or collapsed | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
// Function to toggle the isOpen state on click | ||
const handleToggle = () => { | ||
setIsOpen(prevIsOpen => !prevIsOpen); | ||
}; | ||
|
||
function truncateStyle(string) { | ||
return string.length > 28 ? string.substring(0, 28) + "..." : string; | ||
} | ||
|
||
function handleSelectAll(nodeArray) { | ||
parent.postMessage( | ||
{ | ||
pluginMessage: { | ||
type: "select-multiple-layers", | ||
nodeArray: nodeArray | ||
} | ||
}, | ||
"*" | ||
); | ||
} | ||
|
||
// Helper function to convert the first letter to uppercase and the rest to lowercase | ||
function capitalizeFirstLetter(str) { | ||
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase(); | ||
} | ||
|
||
// Conditionally apply the "open" class based on the isOpen state | ||
const listItemClass = isOpen | ||
? "overview-list-item list-item--open" | ||
: "overview-list-item"; | ||
|
||
return ( | ||
<li className={listItemClass} key={index}> | ||
<div className="overview-content" onClick={handleToggle}> | ||
<StyleContent | ||
style={style} | ||
type={style.type.toLowerCase()} | ||
error={style} | ||
/> | ||
<img | ||
className="overview-icon overview-content-select" | ||
src={require("../assets/select-all.svg")} | ||
/> | ||
<img | ||
className="overview-icon overview-content-arrow" | ||
src={require("../assets/chevron.svg")} | ||
/> | ||
{/* <span className="overview-style-name">{truncateStyle(style.name)}</span> */} | ||
</div> | ||
<ul className="consumer-sublist"> | ||
{Object.entries(style.groupedConsumers).map(([nodeType, nodeIds]) => ( | ||
<li | ||
className="consumer-sublist-item" | ||
key={`${style.name}-${nodeType}`} | ||
onClick={() => handleSelectAll(nodeIds)} // Pass the array of node IDs | ||
> | ||
<img | ||
className="sublist-item-icon" | ||
src={require(`../assets/${nodeType.toLowerCase()}.svg`)} | ||
/> | ||
<span> | ||
<span className="sublist-item-count">{nodeIds.length}</span>{" "} | ||
{capitalizeFirstLetter(nodeType)} Layers | ||
</span> | ||
</li> | ||
))} | ||
</ul> | ||
</li> | ||
); | ||
} | ||
|
||
export default ListItem; |
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,27 @@ | ||
import * as React from "react"; | ||
import StyleListItem from "./StyleListItem"; | ||
|
||
const StylesPage = ({ stylesInUse }) => { | ||
const hasStylesInUse = stylesInUse && stylesInUse.length > 0; | ||
|
||
return ( | ||
<div className="styles-overview-wrapper"> | ||
<div> | ||
<h4>Styles</h4> | ||
<p>Overview of how styles are used in your page.</p> | ||
</div> | ||
{stylesInUse && ( | ||
<div> | ||
<h4>Fills</h4> | ||
<ul className="style-overview-list"> | ||
{stylesInUse.fills.map((style, index) => ( | ||
<StyleListItem style={style} index={index} /> | ||
))} | ||
</ul> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default StylesPage; |
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.