-
Notifications
You must be signed in to change notification settings - Fork 253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ui5-color-palette): initial implementation #2731
Merged
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
00341d1
initial change
tsanislavgatev f54661f
ColorPaletteEntry exptracted into new control and styles fixed
tsanislavgatev 2ff1e1e
the maximum swatches is now fixed
tsanislavgatev e938557
fixed indexing and added new tests
tsanislavgatev 58b5a60
Merge branch 'master' of https://github.com/tsanislavgatev/ui5-webcom…
tsanislavgatev 8b56df3
Tests pushed, localisation fixed
tsanislavgatev 5fd1de7
fixed documentation
tsanislavgatev c8be99c
fixed comments
tsanislavgatev 54f337f
fixed comments and changed name of the inner component
tsanislavgatev ec64a42
Merge branch 'master' of https://github.com/tsanislavgatev/ui5-webcom…
tsanislavgatev 56d106e
Fixed comments
tsanislavgatev ecc05a2
remove changes in wdio
tsanislavgatev 8a85b06
remove changes in wdio
tsanislavgatev d5db40d
fix documentation
tsanislavgatev baa5e58
Added IE support
tsanislavgatev 3d84730
lint fix
tsanislavgatev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div class="ui5-cp-swatch-container" | ||
role="region" | ||
aria-label="{{colorContainerLabel}}"> | ||
{{#each entries}} | ||
<slot | ||
name="{{this.item._individualSlot}}" | ||
@click={{../_onclick}} | ||
@keyup={{../_onkeyup}} | ||
index="{{index}}"> | ||
</slot> | ||
{{/each}} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js"; | ||
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js"; | ||
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js"; | ||
import ItemNavigation from "@ui5/webcomponents-base/dist/delegate/ItemNavigation.js"; | ||
import CSSColor from "@ui5/webcomponents-base/dist/types/CSSColor.js"; | ||
import ItemNavigationBehavior from "@ui5/webcomponents-base/dist/types/ItemNavigationBehavior.js"; | ||
import { | ||
isSpace, | ||
isEnter, | ||
} from "@ui5/webcomponents-base/dist/Keys.js"; | ||
import ColorPaletteTemplate from "./generated/templates/ColorPaletteTemplate.lit.js"; | ||
import ColorPaletteEntry from "./ColorPaletteEntry.js"; | ||
import { | ||
COLORPALETTE_CONTAINER_LABEL, | ||
} from "./generated/i18n/i18n-defaults.js"; | ||
|
||
// Styles | ||
import ColorPaletteCss from "./generated/themes/ColorPalette.css.js"; | ||
|
||
/** | ||
* @public | ||
*/ | ||
const metadata = { | ||
tag: "ui5-color-palette", | ||
managedSlots: true, | ||
properties: /** @lends sap.ui.webcomponents.main.ColorPalette.prototype */ { | ||
/** | ||
* @type {CSSColor} | ||
* @public | ||
tsanislavgatev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
value: { | ||
type: CSSColor, | ||
}, | ||
|
||
entries: { | ||
type: Object, | ||
tsanislavgatev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
multiple: true, | ||
}, | ||
}, | ||
slots: /** @lends sap.ui.webcomponents.main.ColorPalette.prototype */ { | ||
/** | ||
* @type {HTMLElement[]} | ||
* @slot | ||
* @public | ||
*/ | ||
"default": { | ||
propertyName: "colors", | ||
type: HTMLElement, | ||
invalidateOnChildChange: true, | ||
individualSlots: true, | ||
}, | ||
}, | ||
events: /** @lends sap.ui.webcomponents.main.ColorPalette.prototype */ { | ||
change: { | ||
details: { | ||
color: { | ||
tsanislavgatev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type: "CSSColor", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
/** | ||
* @class | ||
* | ||
* <h3 class="comment-api-title">Overview</h3> | ||
* | ||
tsanislavgatev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* <h3>Usage</h3> | ||
* | ||
* For the <code>ui5-color-palette</code> | ||
* <h3>ES6 Module Import</h3> | ||
* | ||
* <code>import @ui5/webcomponents/dist/ColorPalette.js";</code> | ||
* | ||
* @constructor | ||
ilhan007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @author SAP SE | ||
* @alias sap.ui.webcomponents.main.ColorPalette | ||
ilhan007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @extends UI5Element | ||
* @tagname ui5-color-palette | ||
* @since 1.0.0-rc.12 | ||
* @appenddocs ColorPaletteEntry | ||
* @public | ||
*/ | ||
class ColorPalette extends UI5Element { | ||
static get metadata() { | ||
return metadata; | ||
} | ||
|
||
static get render() { | ||
return litRender; | ||
} | ||
|
||
static get styles() { | ||
return ColorPaletteCss; | ||
} | ||
|
||
static get template() { | ||
return ColorPaletteTemplate; | ||
} | ||
|
||
static get dependencies() { | ||
return [ColorPaletteEntry]; | ||
} | ||
|
||
static async onDefine() { | ||
tsanislavgatev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await fetchI18nBundle("@ui5/webcomponents"); | ||
} | ||
|
||
constructor() { | ||
tsanislavgatev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
super(); | ||
this.i18nBundle = getI18nBundle("@ui5/webcomponents"); | ||
this._itemNavigation = new ItemNavigation(this, { | ||
tsanislavgatev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
getItemsCallback: () => this.colors.slice(0, 15), | ||
tsanislavgatev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rowSize: 5, | ||
behavior: ItemNavigationBehavior.Cyclic, | ||
}); | ||
} | ||
|
||
onBeforeRendering() { | ||
this.colors.forEach((item, index) => { | ||
item.index = index + 1; | ||
this.entries.push({ item, index }); | ||
}); | ||
} | ||
|
||
selectColor(target) { | ||
tsanislavgatev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
target.getDomRef().focus(); | ||
tsanislavgatev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this._itemNavigation.update(target); | ||
|
||
this.value = target.value; | ||
|
||
this.fireEvent("change", { | ||
color: this.value, | ||
}); | ||
} | ||
|
||
_onclick(event) { | ||
this.selectColor(event.target); | ||
} | ||
|
||
_onkeyup(event) { | ||
const target = event.target; | ||
|
||
event.preventDefault(); | ||
tsanislavgatev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
event.stopPropagation(); | ||
|
||
if (isEnter(event) || isSpace(event)) { | ||
this.selectColor(target); | ||
} | ||
} | ||
|
||
get colorContainerLabel() { | ||
return this.i18nBundle.getText(COLORPALETTE_CONTAINER_LABEL); | ||
} | ||
} | ||
|
||
ColorPalette.define(); | ||
|
||
export default ColorPalette; |
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,12 @@ | ||
<div | ||
id="color-swatch-{{index}}" | ||
class="ui5-cp-swatch" | ||
style="background-color: {{value}}" | ||
value="{{value}}" | ||
tabindex="{{_tabIndex}}" | ||
role="button" | ||
index="{{index}}" | ||
tsanislavgatev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
aria-label="{{colorLabel}} {{index}}: {{this.value}}" | ||
title="{{colorLabel}} {{index}}: {{this.value}}" | ||
> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js"; | ||
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js"; | ||
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js"; | ||
import CSSColor from "@ui5/webcomponents-base/dist/types/CSSColor.js"; | ||
import ColorPaletteEntryTemplate from "./generated/templates/ColorPaletteEntryTemplate.lit.js"; | ||
import { | ||
COLORPALETTE_COLOR_LABEL, | ||
} from "./generated/i18n/i18n-defaults.js"; | ||
|
||
// Styles | ||
import ColorPaletteEntryCss from "./generated/themes/ColorPaletteEntry.css.js"; | ||
|
||
/** | ||
* @public | ||
*/ | ||
const metadata = { | ||
tag: "ui5-color-palette-entry", | ||
managedSlots: true, | ||
properties: /** @lends sap.ui.webcomponents.main.ColorPaletteEntry.prototype */ { | ||
/** | ||
* Defines the value of the <code>ui5-color-palette</code> inside an HTML Form element when this <code>ui5-color-palette-entry</code> is presented. | ||
tsanislavgatev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @type {CSSColor} | ||
* @public | ||
*/ | ||
value: { | ||
type: CSSColor, | ||
}, | ||
|
||
/** | ||
* Defines the stable selector that you can use via getStableDomRef method. | ||
* @public | ||
*/ | ||
stableDomRef: { | ||
type: String, | ||
}, | ||
/** | ||
* Defines the tab-index of the element, helper information for the ItemNavigation. | ||
* @private | ||
*/ | ||
_tabIndex: { | ||
type: String, | ||
defaultValue: "-1", | ||
noAttribute: true, | ||
}, | ||
|
||
index: { | ||
type: String, | ||
}, | ||
}, | ||
slots: { | ||
}, | ||
events: /** @lends sap.ui.webcomponents.main.ColorPaletteEntry.prototype */ {}, | ||
}; | ||
|
||
/** | ||
* @class | ||
* | ||
* <h3 class="comment-api-title">Overview</h3> | ||
* | ||
* The <code>ui5-color-palette-entry</code> component defines the content of an color in the <code>ui5-color-palette</code>. | ||
* | ||
* @constructor | ||
* @author SAP SE | ||
ilhan007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @alias sap.ui.webcomponents.main.ColorPaletteEntry | ||
* @extends sap.ui.webcomponents.base.UI5Element | ||
* @tagname ui5-color-palette-entry | ||
* @since 1.0.0-rc.12 | ||
* @public | ||
*/ | ||
class ColorPaletteEntry extends UI5Element { | ||
static get metadata() { | ||
return metadata; | ||
} | ||
|
||
static get render() { | ||
return litRender; | ||
} | ||
|
||
static get styles() { | ||
return ColorPaletteEntryCss; | ||
} | ||
|
||
static get template() { | ||
return ColorPaletteEntryTemplate; | ||
} | ||
|
||
static async onDefine() { | ||
await fetchI18nBundle("@ui5/webcomponents"); | ||
} | ||
|
||
constructor() { | ||
super(); | ||
this.i18nBundle = getI18nBundle("@ui5/webcomponents"); | ||
} | ||
|
||
onBeforeRendering() { | ||
tsanislavgatev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
get colorLabel() { | ||
return this.i18nBundle.getText(COLORPALETTE_COLOR_LABEL); | ||
} | ||
} | ||
|
||
ColorPaletteEntry.define(); | ||
|
||
export default ColorPaletteEntry; |
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,7 @@ | ||
.ui5-cp-swatch-container { | ||
tsanislavgatev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
display: flex; | ||
max-width: var(--_ui5_color-palette-row-width); | ||
flex-flow: wrap; | ||
max-height: var(--_ui5_color-palette-row-height); | ||
overflow: hidden; | ||
} |
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,29 @@ | ||
.ui5-cp-swatch { | ||
height: var(--_ui5_color-palette-swatch-height); | ||
width: var(--_ui5_color-palette-swatch-height); | ||
border: 1px solid var(--sapContent_ForegroundBorderColor); | ||
border-radius: 0.25rem; | ||
display: inline-block; | ||
margin: var(--_ui5_color-palette-swatch-margin); | ||
} | ||
|
||
.ui5-cp-swatch:focus:before { | ||
content: ""; | ||
width: var(--_ui5_color-palette-swatch-focus-height); | ||
height: var(--_ui5_color-palette-swatch-focus-height); | ||
margin: 2px; | ||
position: fixed; | ||
outline: rgb(0, 0, 0) dotted 0.0625rem; | ||
} | ||
|
||
.ui5-cp-swatch:focus { | ||
pointer-events: none; | ||
outline: white solid 0.0625rem; | ||
outline-offset: -3px; | ||
} | ||
|
||
.ui5-cp-swatch:hover { | ||
height: var(--_ui5_color-palette-swatch-hover-height); | ||
width: var(--_ui5_color-palette-swatch-hover-height); | ||
margin: var(--_ui5_color-palette-swatch-hover-margin); | ||
} |
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,12 @@ | ||
:root { | ||
--_ui5_color-palette-swatch-height: 1.75rem; | ||
--_ui5_color-palette-swatch-container-sides-padding: 0.3125rem; | ||
--_ui5_color-palette-swatch-container-rows-padding: 0.6875rem; | ||
--_ui5_color-palette-swatch-focus-height: 1.5rem; | ||
--_ui5_color-palette-swatch-container-padding: var(--_ui5_color-palette-swatch-container-sides-padding) var(--_ui5_color-palette-swatch-container-rows-padding); | ||
--_ui5_color-palette-swatch-hover-height: 2.25rem; | ||
--_ui5_color-palette-swatch-margin: calc(var(--_ui5_color-palette-swatch-hover-height) - var(--_ui5_color-palette-swatch-height)); | ||
--_ui5_color-palette-swatch-hover-margin: calc(var(--_ui5_color-palette-swatch-margin) / 2); | ||
--_ui5_color-palette-row-width: 14.375rem; | ||
--_ui5_color-palette-row-height: 9.5rem; | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should import ColorPaletteEntry always (with the ColorPalette).