-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: Improve preview and show changed state
- Loading branch information
Showing
13 changed files
with
1,574 additions
and
604 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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,62 @@ | ||
// @ts-ignore | ||
import React, { PureComponent, Fragment } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { nanoid } from "nanoid"; | ||
import style from "./style.module.css"; | ||
import clsx from "clsx"; | ||
|
||
export default class OptionPreview extends PureComponent { | ||
static propTypes = { | ||
option: PropTypes.shape({ | ||
label: PropTypes.string.isRequired, | ||
colors: PropTypes.arrayOf(PropTypes.string), | ||
}), | ||
}; | ||
|
||
render() { | ||
const { option, onClick, isHighlighted, onMouseEnter } = this.props; | ||
const { colors, label } = option; | ||
|
||
const length = colors.length; | ||
const stop = 100 / length; | ||
const id = "bg-" + nanoid(); | ||
const width = 90; | ||
const height = 60; | ||
|
||
return ( | ||
<button | ||
className={clsx(style.preview, isHighlighted && style.highlighted)} | ||
onClick={onClick} | ||
onMouseEnter={onMouseEnter} | ||
type="button" | ||
> | ||
<svg | ||
height={height} | ||
width={width} | ||
version="1.1" | ||
xmlns="http://www.w3.org/2000/svg" | ||
xmlnsXlink="http://www.w3.org/1999/xlink" | ||
preserveAspectRatio="none" | ||
className="pointer-events-none size-full" | ||
> | ||
<defs> | ||
<linearGradient x1="0%" y1="100%" x2="100%" y2="100%" id={id}> | ||
{colors.map((color, index) => { | ||
const start = stop * index + "%"; | ||
const end = stop * (index + 1) + "%"; | ||
return ( | ||
<Fragment key={index}> | ||
<stop stopColor={color} offset={start}></stop> | ||
<stop stopColor={color} offset={end}></stop> | ||
</Fragment> | ||
); | ||
})} | ||
</linearGradient> | ||
</defs> | ||
<rect fill={`url(#${id})`} x="0" y="0" width={width} height={height}></rect> | ||
</svg> | ||
<span title={label}>{label}</span> | ||
</button> | ||
) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Resources/Private/Editor/src/OptionPreview/style.module.css
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 @@ | ||
.preview { | ||
cursor: pointer; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
line-height: calc(var(--spacing-GoldenUnit) - 10px); | ||
padding: 5px var(--spacing-Full); | ||
overflow: hidden; | ||
display: flex; | ||
gap: var(--spacing-Full); | ||
align-items: center; | ||
border: 0; | ||
background: none; | ||
border-radius: 0; | ||
color: white; | ||
width: 100%; | ||
|
||
& svg { | ||
display: block; | ||
margin-left: calc(var(--spacing-Full) * -1); | ||
margin-block: -5px; | ||
height: 60px; | ||
} | ||
} | ||
|
||
.highlighted { | ||
background-color: var(--colors-PrimaryBlue); | ||
} |
Oops, something went wrong.