diff --git a/CHANGELOG.md b/CHANGELOG.md index bd9cf3dd6..cc976e773 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ + +# [1.0.0-rc.14](https://github.com/deckgo/deckdeckgo/compare/v1.0.0-rc.13...v1.0.0-14) (2019-09-XX) + + +### Others + +* utils: v1.0.0-rc.1-2 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/utils/CHANGELOG.md)) + # [1.0.0-rc.13](https://github.com/deckgo/deckdeckgo/compare/v1.0.0-rc.12-3...v1.0.0-13) (2019-09-20) diff --git a/docs/docs/components/app-components-color/app-components-color.md b/docs/docs/components/app-components-color/app-components-color.md new file mode 100644 index 000000000..3a8e52f69 --- /dev/null +++ b/docs/docs/components/app-components-color/app-components-color.md @@ -0,0 +1,224 @@ +# Color Picker + +The "Color Picker" component is a simple component to, guess what, allow your users to "pick colors" 😉 + +It is fully configurable in terms of colors, you could define the set of colors you rather like to offer and it also implements a "more" action which, if clicked, will open the platform standard color picker. + +## Table of contents + +- [Showcase](#app-components-color-showcase) +- [Installation](#app-components-color-installation) + - [Using from a CDN](#app-components-color-from-a-cdn) + - [Install from NPM](#app-components-color-from-npm) + - [Framework integration](#app-components-color-framework-integration) +- [Usage](#app-components-color-usage) + - [Slots](#app-components-color-slots) + - [Attributes](#app-components-color-attributes) + - [Theming](#app-components-color-theming) + - [Methods](#app-components-color-methods) +- [Trying it out](#app-components-color-trying-it-out) + +## Showcase + +
+ + ... + +
+ +## Installation + +This component could be added to your web application using the following methods. + +### Using from a CDN + +It's recommended to use [unpkg](https://unpkg.com/) to use the [DeckDeckGo] lazy image component from a CDN. To do so, add the following include script in the main HTML file of your project: + +``` + + +``` +### Install from NPM + +Install it in your project from [npm](https://www.npmjs.com/package/@deckdeckgo/qrcode) using the following command: + +```bash +npm install @deckdeckgo/color +``` + +### Framework integration + +The [Stencil documentation](https://stenciljs.com/docs/overview) provide examples of framework integration for [Angular](https://stenciljs.com/docs/angular), [React](https://stenciljs.com/docs/react), [Vue](https://stenciljs.com/docs/vue) and [Ember](https://stenciljs.com/docs/ember). + +That being said, commonly, you might either `import` or `load` it: + +#### Import + +``` +import '@deckdeckgo/color'; +``` + +#### Loader + +``` +import { defineCustomElements as deckDeckGoElement } from '@deckdeckgo/color/dist/loader'; +deckDeckGoElement(window); +``` + +## Usage + +The "Color Picker" Web Component could be integrated using the tag ``. + +``` + + ... + +``` + +### Slots + +The slot `more` is optional, moreover, the "more" action itself could be turned off. + +### Attributes + +This component offers the following options which could be set using attributes: + +| Property | Attribute | Description | Type | Default | +| ---------- | ----------- | ----------- | --------------------- | ----------------- | +| `colorHex` | `color-hex` | The current selected color provided as hexadecimal value. | `string` | `undefined` | +| `more` | `more` | In case you would not like to offer the "more" options. | `boolean` | `true` | +| `moreAlt` | `more-alt` | An accessibility label for the "more action. | `string` | `'More'` | +| `palette` | | The palette of color (see here under). | `DeckdeckgoPalette[]` | `DEFAULT_PALETTE` | + +#### Palette + +The `palette` attribute is a complex object and therefore could only be set using Javascript. + +It is defined as the following: + +``` +export interface DeckdeckgoPaletteColor { + hex: string; + rgb?: string; +} + +export interface DeckdeckgoPalette { + color: DeckdeckgoPaletteColor; + alt?: string; +} +``` + +The key value is the color provided as `hex` value. The `rgb` value is use for presentation purpose, for the hover action and the highlight of the selected color. + +The default palette is the following: + +``` +export const DEFAULT_PALETTE: DeckdeckgoPalette[] = [ + { + color: { + hex: '#FF6900', + rgb: '255,105,0' + }, + alt: 'Orange' + }, + { + color: { + hex: '#FCB900', + rgb: '252,185,0' + }, + alt: 'Yellow' + }, + { + color: { + hex: '#7BDCB5', + rgb: '123,220,181' + }, + alt: 'Light green' + }, + { + color: { + hex: '#00D084', + rgb: '0,208,132' + }, + alt: 'Green' + }, + { + color: { + hex: '#8ED1FC', + rgb: '142,209,252' + }, + alt: 'Light blue' + }, + { + color: { + hex: '#0693E3', + rgb: '6,147,227' + }, + alt: 'Blue' + }, + { + color: { + hex: '#ABB8C3', + rgb: '171,184,195' + }, + alt: 'Grey' + }, + { + color: { + hex: '#EB144C', + rgb: '235,20,76' + }, + alt: 'Red' + }, + { + color: { + hex: '#F78DA7', + rgb: '247,141,167' + }, + alt: 'Pink' + }, + { + color: { + hex: '#9900EF', + rgb: '153,0,239' + }, + alt: 'Violet' + }, + { + color: { + hex: '#000000', + rgb: '0,0,0' + }, + alt: 'Black' + } +]; +``` + +### Theming + +The following theming options will affect this component if set on its host or parent. + +| CSS4 variable | Default | Note | +| -------------------------- |-----------------|-----------------| +| --deckgo-button-width | 28px | The width of a button to select a color and the more button | +| --deckgo-button-height | 28px | The height of a button to select a color and the more button | +| --deckgo-button-margin | 4px | The margin of a button to select a color and the more button | +| --deckgo-button-outline | none | The outline of a button to select a color and the more button | +| --deckgo-button-border | none | The border of a button to select a color and the more button | +| --deckgo-button-border-radius | 50% | The border radius of a button to select a color | +| --deckgo-button-more-border-radius | | The border radius of the more button | +| --deckgo-button-more-border | | The border of the more button | + +### Events + +To listen to the selected color you have to subscribe to the following event: + +| Event | Description | Type | +| ------------- | ----------- | ------------------------------------- | +| `colorChange` | Emit the selected color. | `CustomEvent` | + +In case the platform color picker would be use by the user, the change will be triggered multiple times, as long as the user change its value in the platform picker. + +For the definition of the type of the event, see above description of `DeckdeckgoPaletteColor`. + +[DeckDeckGo]: https://deckdeckgo.com \ No newline at end of file diff --git a/docs/docs/components/app-components-lazy-img/app-components-lazy-img.md b/docs/docs/components/app-components-lazy-img/app-components-lazy-img.md index 40491bdac..1ff0a064c 100644 --- a/docs/docs/components/app-components-lazy-img/app-components-lazy-img.md +++ b/docs/docs/components/app-components-lazy-img/app-components-lazy-img.md @@ -9,8 +9,8 @@ An `` tag is per default use to display the image but optionally it could ## Table of contents - [Installation](#app-components-lazy-img-installation) - - [Using from a CDN](#app-components-from-a-cdn) - - [Install from NPM](#app-components-from-npm) + - [Using from a CDN](#app-components-lazy-img-from-a-cdn) + - [Install from NPM](#app-components-lazy-img-from-npm) - [Framework integration](#app-components-lazy-img-framework-integration) - [Usage](#app-components-lazy-img-usage) - [Slots](#app-components-lazy-img-slots) diff --git a/docs/package-lock.json b/docs/package-lock.json index 70c5a8f24..0fa55cff4 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -29,6 +29,173 @@ "date-fns": "^2.0.1" } }, + "@deckdeckgo/color": { + "version": "file:../webcomponents/color", + "dependencies": { + "@stencil/core": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@stencil/core/-/core-1.4.0.tgz", + "integrity": "sha512-/iI87p7XsqE3U96ykx4SSY/btv9jZguI3JkG8RaTNlQipPUmPb0JmLei8sgijTUD/fY5TFuE3L1o8hwLI0rW3A==", + "requires": { + "typescript": "3.6.2" + } + }, + "@stencil/postcss": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@stencil/postcss/-/postcss-1.0.1.tgz", + "integrity": "sha512-+QOLwdiMSeE6XbvjOM8bfMIX6E6L4DFLmnp0wZqCj4O/PVkNfEQA6IXZgd6F+OIfZ1wBy/dxR4Jvtwfo+QXa2g==", + "requires": { + "postcss": "~7.0.17" + } + }, + "@stencil/sass": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@stencil/sass/-/sass-1.0.1.tgz", + "integrity": "sha512-3vmF8zir9FcVY/tYW0/V/pWrYSU684eASmALL2v29PGJvX6/CXh9n8LF7Jy95SpJPij3lisIUXLls7edXy2hYg==" + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "requires": { + "color-convert": "^1.9.0" + } + }, + "autoprefixer": { + "version": "9.6.1", + "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.6.1.tgz", + "integrity": "sha512-aVo5WxR3VyvyJxcJC3h4FKfwCQvQWb1tSI5VHNibddCVWrcD1NvlxEweg3TSgiPztMnWfjpy2FURKA2kvDE+Tw==", + "requires": { + "browserslist": "^4.6.3", + "caniuse-lite": "^1.0.30000980", + "chalk": "^2.4.2", + "normalize-range": "^0.1.2", + "num2fraction": "^1.2.2", + "postcss": "^7.0.17", + "postcss-value-parser": "^4.0.0" + } + }, + "browserslist": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.7.0.tgz", + "integrity": "sha512-9rGNDtnj+HaahxiVV38Gn8n8Lr8REKsel68v1sPFfIGEK6uSXTY3h9acgiT1dZVtOOUtifo/Dn8daDQ5dUgVsA==", + "requires": { + "caniuse-lite": "^1.0.30000989", + "electron-to-chromium": "^1.3.247", + "node-releases": "^1.1.29" + } + }, + "caniuse-lite": { + "version": "1.0.30000989", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000989.tgz", + "integrity": "sha512-vrMcvSuMz16YY6GSVZ0dWDTJP8jqk3iFQ/Aq5iqblPwxSVVZI+zxDyTX0VPqtQsDnfdrBDcsmhgTEOh5R8Lbpw==" + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "dependencies": { + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + }, + "electron-to-chromium": { + "version": "1.3.263", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.263.tgz", + "integrity": "sha512-VfPi+sE/1nEKOV7DWDqWSUGP7ztJG5FeqHbMEj6dBb/arKnxpOCnRXOSC6HBV6qTfK5v8CX7xWCqzN36UqG1oA==" + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" + }, + "node-releases": { + "version": "1.1.32", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.32.tgz", + "integrity": "sha512-VhVknkitq8dqtWoluagsGPn3dxTvN9fwgR59fV3D7sLBHe0JfDramsMI8n8mY//ccq/Kkrf8ZRHRpsyVZ3qw1A==", + "requires": { + "semver": "^5.3.0" + } + }, + "normalize-range": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/normalize-range/-/normalize-range-0.1.2.tgz", + "integrity": "sha1-LRDAa9/TEuqXd2laTShDlFa3WUI=" + }, + "num2fraction": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/num2fraction/-/num2fraction-1.2.2.tgz", + "integrity": "sha1-b2gragJ6Tp3fpFZM0lidHU5mnt4=" + }, + "postcss": { + "version": "7.0.18", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.18.tgz", + "integrity": "sha512-/7g1QXXgegpF+9GJj4iN7ChGF40sYuGYJ8WZu8DZWnmhQ/G36hfdk3q9LBJmoK+lZ+yzZ5KYpOoxq7LF1BxE8g==", + "requires": { + "chalk": "^2.4.2", + "source-map": "^0.6.1", + "supports-color": "^6.1.0" + } + }, + "postcss-value-parser": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.0.2.tgz", + "integrity": "sha512-LmeoohTpp/K4UiyQCwuGWlONxXamGzCMtFxLq4W1nZVGIQLYvMCJx3yAF9qyyuFpflABI9yVdtJAqbihOsCsJQ==" + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + }, + "supports-color": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz", + "integrity": "sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==", + "requires": { + "has-flag": "^3.0.0" + } + }, + "typescript": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.2.tgz", + "integrity": "sha512-lmQ4L+J6mnu3xweP8+rOrUwzmN+MRAj7TgtJtDaXE5PMyX2kCrklhg3rvOsOIfNeAWMQWO2F1GPc1kMD2vLAfw==" + } + } + }, "@deckdeckgo/core": { "version": "1.0.0-rc.1", "resolved": "https://registry.npmjs.org/@deckdeckgo/core/-/core-1.0.0-rc.1.tgz", diff --git a/docs/package.json b/docs/package.json index 133d7b1f4..c3a669859 100644 --- a/docs/package.json +++ b/docs/package.json @@ -15,6 +15,7 @@ }, "dependencies": { "@deckdeckgo/charts": "^1.0.0-rc.1", + "@deckdeckgo/color": "file:../webcomponents/color", "@deckdeckgo/core": "^1.0.0-rc.1", "@deckdeckgo/highlight-code": "^1.0.0-rc.1", "@deckdeckgo/inline-editor": "^1.0.0-rc.1", diff --git a/docs/src/app/app-root.tsx b/docs/src/app/app-root.tsx index c9f850cf0..fbfd979d5 100644 --- a/docs/src/app/app-root.tsx +++ b/docs/src/app/app-root.tsx @@ -55,6 +55,7 @@ export class AppRoot { + @@ -120,6 +121,7 @@ export class AppRoot { Components Charts + Color Picker Gif Highlight Code Lazy Image diff --git a/docs/src/app/pages/docs/components/app-components-color/app-components-color.tsx b/docs/src/app/pages/docs/components/app-components-color/app-components-color.tsx new file mode 100644 index 000000000..e0ecd6f7b --- /dev/null +++ b/docs/src/app/pages/docs/components/app-components-color/app-components-color.tsx @@ -0,0 +1,199 @@ +import {Component, Element, h} from '@stencil/core'; + +import {DeckdeckgoDocsUtils} from '../../../../utils/deckdeckgo-docs-utils'; + +@Component({ + tag: 'app-components-color' +}) +export class AppComponentsColor { + + @Element() el: HTMLElement; + + async componentDidLoad() { + await DeckdeckgoDocsUtils.reloadCode(this.el); + } + + render() { + return [ + , + + +

Color Picker

+

The "Color Picker" component is a simple component to, guess what, allow your users to "pick colors" 😉

+

It is fully configurable in terms of colors, you could define the set of colors you rather like to offer and it also implements a "more" action which, if clicked, will open the platform standard color picker.

+

Table of contents

+ +

Showcase

+
+ + ... + +
+ +

Installation

+

This component could be added to your web application using the following methods.

+

Using from a CDN

+

It's recommended to use unpkg to use the DeckDeckGo lazy image component from a CDN. To do so, add the following include script in the main HTML file of your project:

+ + <script type="module" src="https://unpkg.com/@deckdeckgo/color@latest/dist/deckdeckgo-color/deckdeckgo-color.esm.js"></script>{'\n'}<script nomodule="" src="https://unpkg.com/@deckdeckgo/color@latest/dist/deckdeckgo-color/deckdeckgo-color.js"></script> +

Install from NPM

+

Install it in your project from npm using the following command:

+ + npm install @deckdeckgo/color +

Framework integration

+

The Stencil documentation provide examples of framework integration for Angular, React, Vue and Ember.

+

That being said, commonly, you might either import or load it:

+

Import

+ + import '@deckdeckgo/color'; +

Loader

+ + import { defineCustomElements as deckDeckGoElement } from '@deckdeckgo/color/dist/loader';{'\n'}deckDeckGoElement(window); +

Usage

+

The "Color Picker" Web Component could be integrated using the tag <deckgo-color/>.

+ + <deckgo-color>{'\n'} <span slot="more">...</span>{'\n'}</deckgo-color> +

Slots

+

The slot more is optional, moreover, the "more" action itself could be turned off.

+

Attributes

+

This component offers the following options which could be set using attributes:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyAttributeDescriptionTypeDefault
colorHexcolor-hexThe current selected color provided as hexadecimal value.stringundefined
moremoreIn case you would not like to offer the "more" options.booleantrue
moreAltmore-altAn accessibility label for the "more action.string'More'
paletteThe palette of color (see here under).DeckdeckgoPalette[]DEFAULT_PALETTE
+

Palette

+

The palette attribute is a complex object and therefore could only be set using Javascript.

+

It is defined as the following:

+ + export interface DeckdeckgoPaletteColor {{'\n'} hex: string;{'\n'} rgb?: string;{'\n'}}{'\n'}{'\n'}export interface DeckdeckgoPalette {{'\n'} color: DeckdeckgoPaletteColor;{'\n'} alt?: string;{'\n'}} +

The key value is the color provided as hex value. The rgb value is use for presentation purpose, for the hover action and the highlight of the selected color.

+

The default palette is the following:

+ + export const DEFAULT_PALETTE: DeckdeckgoPalette[] = [{'\n'} {{'\n'} color: {{'\n'} hex: '#FF6900',{'\n'} rgb: '255,105,0'{'\n'} },{'\n'} alt: 'Orange'{'\n'} },{'\n'} {{'\n'} color: {{'\n'} hex: '#FCB900',{'\n'} rgb: '252,185,0'{'\n'} },{'\n'} alt: 'Yellow'{'\n'} },{'\n'} {{'\n'} color: {{'\n'} hex: '#7BDCB5',{'\n'} rgb: '123,220,181'{'\n'} },{'\n'} alt: 'Light green'{'\n'} },{'\n'} {{'\n'} color: {{'\n'} hex: '#00D084',{'\n'} rgb: '0,208,132'{'\n'} },{'\n'} alt: 'Green'{'\n'} },{'\n'} {{'\n'} color: {{'\n'} hex: '#8ED1FC',{'\n'} rgb: '142,209,252'{'\n'} },{'\n'} alt: 'Light blue'{'\n'} },{'\n'} {{'\n'} color: {{'\n'} hex: '#0693E3',{'\n'} rgb: '6,147,227'{'\n'} },{'\n'} alt: 'Blue'{'\n'} },{'\n'} {{'\n'} color: {{'\n'} hex: '#ABB8C3',{'\n'} rgb: '171,184,195'{'\n'} },{'\n'} alt: 'Grey'{'\n'} },{'\n'} {{'\n'} color: {{'\n'} hex: '#EB144C',{'\n'} rgb: '235,20,76'{'\n'} },{'\n'} alt: 'Red'{'\n'} },{'\n'} {{'\n'} color: {{'\n'} hex: '#F78DA7',{'\n'} rgb: '247,141,167'{'\n'} },{'\n'} alt: 'Pink'{'\n'} },{'\n'} {{'\n'} color: {{'\n'} hex: '#9900EF',{'\n'} rgb: '153,0,239'{'\n'} },{'\n'} alt: 'Violet'{'\n'} },{'\n'} {{'\n'} color: {{'\n'} hex: '#000000',{'\n'} rgb: '0,0,0'{'\n'} },{'\n'} alt: 'Black'{'\n'} }{'\n'}]; +

Theming

+

The following theming options will affect this component if set on its host or parent.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CSS4 variableDefaultNote
--deckgo-button-width28pxThe width of a button to select a color and the more button
--deckgo-button-height28pxThe height of a button to select a color and the more button
--deckgo-button-margin4pxThe margin of a button to select a color and the more button
--deckgo-button-outlinenoneThe outline of a button to select a color and the more button
--deckgo-button-bordernoneThe border of a button to select a color and the more button
--deckgo-button-border-radius50%The border radius of a button to select a color
--deckgo-button-more-border-radiusThe border radius of the more button
--deckgo-button-more-borderThe border of the more button
+

Events

+

To listen to the selected color you have to subscribe to the following event:

+ + + + + + + + + + + + + +
EventDescriptionType
colorChangeEmit the selected color.CustomEvent<DeckdeckgoPaletteColor>
+

In case the platform color picker would be use by the user, the change will be triggered multiple times, as long as the user change its value in the platform picker.

+

For the definition of the type of the event, see above description of DeckdeckgoPaletteColor.

+
+ + +
+ ]; + } +} diff --git a/docs/src/app/pages/docs/components/app-components-lazy-img/app-components-lazy-img.tsx b/docs/src/app/pages/docs/components/app-components-lazy-img/app-components-lazy-img.tsx index ca33e374c..33ec1ec36 100644 --- a/docs/src/app/pages/docs/components/app-components-lazy-img/app-components-lazy-img.tsx +++ b/docs/src/app/pages/docs/components/app-components-lazy-img/app-components-lazy-img.tsx @@ -25,8 +25,8 @@ export class AppComponentsLazyImg {

Table of contents

  • Installation
  • diff --git a/docs/src/components.d.ts b/docs/src/components.d.ts index 4f1316ecc..fc6898ae9 100644 --- a/docs/src/components.d.ts +++ b/docs/src/components.d.ts @@ -10,6 +10,7 @@ import { HTMLStencilElement, JSXBase } from '@stencil/core/internal'; export namespace Components { interface AppComponentsCharts {} + interface AppComponentsColor {} interface AppComponentsGif {} interface AppComponentsHighlightCode {} interface AppComponentsInlineEditor {} @@ -78,6 +79,12 @@ declare global { new (): HTMLAppComponentsChartsElement; }; + interface HTMLAppComponentsColorElement extends Components.AppComponentsColor, HTMLStencilElement {} + var HTMLAppComponentsColorElement: { + prototype: HTMLAppComponentsColorElement; + new (): HTMLAppComponentsColorElement; + }; + interface HTMLAppComponentsGifElement extends Components.AppComponentsGif, HTMLStencilElement {} var HTMLAppComponentsGifElement: { prototype: HTMLAppComponentsGifElement; @@ -385,6 +392,7 @@ declare global { }; interface HTMLElementTagNameMap { 'app-components-charts': HTMLAppComponentsChartsElement; + 'app-components-color': HTMLAppComponentsColorElement; 'app-components-gif': HTMLAppComponentsGifElement; 'app-components-highlight-code': HTMLAppComponentsHighlightCodeElement; 'app-components-inline-editor': HTMLAppComponentsInlineEditorElement; @@ -441,6 +449,7 @@ declare global { declare namespace LocalJSX { interface AppComponentsCharts extends JSXBase.HTMLAttributes {} + interface AppComponentsColor extends JSXBase.HTMLAttributes {} interface AppComponentsGif extends JSXBase.HTMLAttributes {} interface AppComponentsHighlightCode extends JSXBase.HTMLAttributes {} interface AppComponentsInlineEditor extends JSXBase.HTMLAttributes {} @@ -501,6 +510,7 @@ declare namespace LocalJSX { interface IntrinsicElements { 'app-components-charts': AppComponentsCharts; + 'app-components-color': AppComponentsColor; 'app-components-gif': AppComponentsGif; 'app-components-highlight-code': AppComponentsHighlightCode; 'app-components-inline-editor': AppComponentsInlineEditor; diff --git a/docs/src/global/app.ts b/docs/src/global/app.ts index 22a8c0d28..f2a5fabbf 100644 --- a/docs/src/global/app.ts +++ b/docs/src/global/app.ts @@ -19,3 +19,4 @@ import '@deckdeckgo/highlight-code'; import '@deckdeckgo/charts'; import '@deckdeckgo/qrcode'; import '@deckdeckgo/inline-editor'; +import '@deckdeckgo/color'; diff --git a/studio/package-lock.json b/studio/package-lock.json index 5888be11e..c12c83b40 100644 --- a/studio/package-lock.json +++ b/studio/package-lock.json @@ -13,6 +13,173 @@ "regenerator-runtime": "^0.13.2" } }, + "@deckdeckgo/color": { + "version": "file:../webcomponents/color", + "dependencies": { + "@stencil/core": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@stencil/core/-/core-1.4.0.tgz", + "integrity": "sha512-/iI87p7XsqE3U96ykx4SSY/btv9jZguI3JkG8RaTNlQipPUmPb0JmLei8sgijTUD/fY5TFuE3L1o8hwLI0rW3A==", + "requires": { + "typescript": "3.6.2" + } + }, + "@stencil/postcss": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@stencil/postcss/-/postcss-1.0.1.tgz", + "integrity": "sha512-+QOLwdiMSeE6XbvjOM8bfMIX6E6L4DFLmnp0wZqCj4O/PVkNfEQA6IXZgd6F+OIfZ1wBy/dxR4Jvtwfo+QXa2g==", + "requires": { + "postcss": "~7.0.17" + } + }, + "@stencil/sass": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@stencil/sass/-/sass-1.0.1.tgz", + "integrity": "sha512-3vmF8zir9FcVY/tYW0/V/pWrYSU684eASmALL2v29PGJvX6/CXh9n8LF7Jy95SpJPij3lisIUXLls7edXy2hYg==" + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "requires": { + "color-convert": "^1.9.0" + } + }, + "autoprefixer": { + "version": "9.6.1", + "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.6.1.tgz", + "integrity": "sha512-aVo5WxR3VyvyJxcJC3h4FKfwCQvQWb1tSI5VHNibddCVWrcD1NvlxEweg3TSgiPztMnWfjpy2FURKA2kvDE+Tw==", + "requires": { + "browserslist": "^4.6.3", + "caniuse-lite": "^1.0.30000980", + "chalk": "^2.4.2", + "normalize-range": "^0.1.2", + "num2fraction": "^1.2.2", + "postcss": "^7.0.17", + "postcss-value-parser": "^4.0.0" + } + }, + "browserslist": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.7.0.tgz", + "integrity": "sha512-9rGNDtnj+HaahxiVV38Gn8n8Lr8REKsel68v1sPFfIGEK6uSXTY3h9acgiT1dZVtOOUtifo/Dn8daDQ5dUgVsA==", + "requires": { + "caniuse-lite": "^1.0.30000989", + "electron-to-chromium": "^1.3.247", + "node-releases": "^1.1.29" + } + }, + "caniuse-lite": { + "version": "1.0.30000989", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000989.tgz", + "integrity": "sha512-vrMcvSuMz16YY6GSVZ0dWDTJP8jqk3iFQ/Aq5iqblPwxSVVZI+zxDyTX0VPqtQsDnfdrBDcsmhgTEOh5R8Lbpw==" + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "dependencies": { + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + }, + "electron-to-chromium": { + "version": "1.3.263", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.263.tgz", + "integrity": "sha512-VfPi+sE/1nEKOV7DWDqWSUGP7ztJG5FeqHbMEj6dBb/arKnxpOCnRXOSC6HBV6qTfK5v8CX7xWCqzN36UqG1oA==" + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" + }, + "node-releases": { + "version": "1.1.32", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.32.tgz", + "integrity": "sha512-VhVknkitq8dqtWoluagsGPn3dxTvN9fwgR59fV3D7sLBHe0JfDramsMI8n8mY//ccq/Kkrf8ZRHRpsyVZ3qw1A==", + "requires": { + "semver": "^5.3.0" + } + }, + "normalize-range": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/normalize-range/-/normalize-range-0.1.2.tgz", + "integrity": "sha1-LRDAa9/TEuqXd2laTShDlFa3WUI=" + }, + "num2fraction": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/num2fraction/-/num2fraction-1.2.2.tgz", + "integrity": "sha1-b2gragJ6Tp3fpFZM0lidHU5mnt4=" + }, + "postcss": { + "version": "7.0.18", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.18.tgz", + "integrity": "sha512-/7g1QXXgegpF+9GJj4iN7ChGF40sYuGYJ8WZu8DZWnmhQ/G36hfdk3q9LBJmoK+lZ+yzZ5KYpOoxq7LF1BxE8g==", + "requires": { + "chalk": "^2.4.2", + "source-map": "^0.6.1", + "supports-color": "^6.1.0" + } + }, + "postcss-value-parser": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.0.2.tgz", + "integrity": "sha512-LmeoohTpp/K4UiyQCwuGWlONxXamGzCMtFxLq4W1nZVGIQLYvMCJx3yAF9qyyuFpflABI9yVdtJAqbihOsCsJQ==" + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + }, + "supports-color": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz", + "integrity": "sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==", + "requires": { + "has-flag": "^3.0.0" + } + }, + "typescript": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.2.tgz", + "integrity": "sha512-lmQ4L+J6mnu3xweP8+rOrUwzmN+MRAj7TgtJtDaXE5PMyX2kCrklhg3rvOsOIfNeAWMQWO2F1GPc1kMD2vLAfw==" + } + } + }, "@deckdeckgo/core": { "version": "1.0.0-rc.1-1", "resolved": "https://registry.npmjs.org/@deckdeckgo/core/-/core-1.0.0-rc.1-1.tgz", @@ -120,9 +287,9 @@ "dev": true }, "@deckdeckgo/utils": { - "version": "1.0.0-rc.1-1", - "resolved": "https://registry.npmjs.org/@deckdeckgo/utils/-/utils-1.0.0-rc.1-1.tgz", - "integrity": "sha512-FYszS7gTAC+V0BQ1CnNyKCkSRWcJw+37vTnMdWwFZzOA2JCYagqKKcZ/vWket8nuu7Q9NpsADoYCX8FMXU34/A==" + "version": "1.0.0-rc.1-2", + "resolved": "https://registry.npmjs.org/@deckdeckgo/utils/-/utils-1.0.0-rc.1-2.tgz", + "integrity": "sha512-wWcUlQz70CpzGaVGeqfxwmT54DyF9cI69HmGGK9bTHLejyIGzJf2dSzzegTOboaV7QS1msk8Pw69xOWzbYx2UQ==" }, "@firebase/app": { "version": "0.4.16", diff --git a/studio/package.json b/studio/package.json index 9273a1b4e..8921e93f1 100644 --- a/studio/package.json +++ b/studio/package.json @@ -14,6 +14,7 @@ "test.watch": "stencil test --spec --e2e --watch" }, "dependencies": { + "@deckdeckgo/color": "file:../webcomponents/color", "@deckdeckgo/core": "^1.0.0-rc.1-1", "@deckdeckgo/highlight-code": "^1.0.0-rc.1-1", "@deckdeckgo/inline-editor": "^1.0.0-rc.1-1", @@ -26,7 +27,7 @@ "@deckdeckgo/slide-split": "^1.0.0-rc.1", "@deckdeckgo/slide-title": "^1.0.0-rc.1", "@deckdeckgo/slide-youtube": "^1.0.0-rc.1-1", - "@deckdeckgo/utils": "^1.0.0-rc.1-1", + "@deckdeckgo/utils": "^1.0.0-rc.1-2", "@ionic/core": "^4.8.1", "firebase": "^6.6.0", "idb-keyval": "^3.2.0", diff --git a/studio/src/app/components/editor/actions/app-editor-actions/app-editor-actions.tsx b/studio/src/app/components/editor/actions/app-editor-actions/app-editor-actions.tsx index dc3605c82..f2a2d06d9 100644 --- a/studio/src/app/components/editor/actions/app-editor-actions/app-editor-actions.tsx +++ b/studio/src/app/components/editor/actions/app-editor-actions/app-editor-actions.tsx @@ -1,6 +1,8 @@ -import {Component, Element, Event, EventEmitter, h, JSX, Listen, Prop} from '@stencil/core'; +import {Component, Element, Event, EventEmitter, h, JSX, Listen, Prop, State} from '@stencil/core'; import {OverlayEventDetail} from '@ionic/core'; +import {isIPad} from '@deckdeckgo/utils'; + import {get, set} from 'idb-keyval'; import {SlideTemplate} from '../../../../models/data/slide'; @@ -45,10 +47,17 @@ export class AppEditorActions { @Event() private openShare: EventEmitter; + @State() + private fullscreenEnable: boolean = true; + constructor() { this.anonymousService = AnonymousService.getInstance(); } + componentWillLoad() { + this.fullscreenEnable = !isIPad(); + } + async onActionOpenSlideAdd($event: CustomEvent) { if (!$event || !$event.detail) { return; @@ -250,9 +259,7 @@ export class AppEditorActions { Slides - this.toggleFullScreenMode()} color="primary" class="wider-devices" mode="md"> - {this.renderFullscreen()} - + {this.renderFullscreenButton()} this.openRemoteControl()} color="primary" class="wider-devices" mode="md"> @@ -275,6 +282,16 @@ export class AppEditorActions { } + private renderFullscreenButton() { + if (this.fullscreenEnable) { + return this.toggleFullScreenMode()} color="primary" class="wider-devices" mode="md"> + {this.renderFullscreen()} + ; + } else { + return undefined; + } + } + private renderFullscreen() { if (this.fullscreen) { return [ diff --git a/studio/src/app/components/editor/app-editor-toolbar/app-editor-toolbar.tsx b/studio/src/app/components/editor/app-editor-toolbar/app-editor-toolbar.tsx index 1d4c67741..c0d6c1ae5 100644 --- a/studio/src/app/components/editor/app-editor-toolbar/app-editor-toolbar.tsx +++ b/studio/src/app/components/editor/app-editor-toolbar/app-editor-toolbar.tsx @@ -32,12 +32,6 @@ export class AppEditorToolbar { @State() private displayed: boolean = false; - @State() - private color: string; - - @State() - private background: string; - private selectedElement: HTMLElement; @State() @@ -347,10 +341,6 @@ export class AppEditorToolbar { this.displayed = true; - const style: CSSStyleDeclaration = window.getComputedStyle(element); - this.color = style.color; - this.background = style.backgroundColor; - resolve(); }); } @@ -733,8 +723,6 @@ export class AppEditorToolbar { component: 'app-color', componentProps: { deckOrSlide: this.deckOrSlide, - color: this.color, - background: this.background, selectedElement: this.selectedElement }, mode: 'md', diff --git a/studio/src/app/popovers/editor/app-color/app-color.scss b/studio/src/app/popovers/editor/app-color/app-color.scss index 3030c61f2..7e30e31e2 100644 --- a/studio/src/app/popovers/editor/app-color/app-color.scss +++ b/studio/src/app/popovers/editor/app-color/app-color.scss @@ -2,9 +2,15 @@ app-color { @import "../../../../global/theme/editor/editor-popover"; - input { - visibility: hidden; - z-index: -1; + deckgo-color { + --deckgo-button-more-border-radius: 50%; + --deckgo-button-more-border: 1px solid var(--ion-color-medium); + } + + ion-icon.more { + font-size: 1.4rem; + padding-top: 2px; + color: var(--ion-color-medium); } } diff --git a/studio/src/app/popovers/editor/app-color/app-color.tsx b/studio/src/app/popovers/editor/app-color/app-color.tsx index 1a6a0216b..28a0f5c23 100644 --- a/studio/src/app/popovers/editor/app-color/app-color.tsx +++ b/studio/src/app/popovers/editor/app-color/app-color.tsx @@ -1,4 +1,6 @@ -import {Component, Element, Event, EventEmitter, h, Prop} from '@stencil/core'; +import {Component, Element, Event, EventEmitter, h, Prop, State} from '@stencil/core'; + +import {isIPad} from '@deckdeckgo/utils'; @Component({ tag: 'app-color', @@ -11,12 +13,6 @@ export class AppColor { @Prop() deckOrSlide: boolean = false; - @Prop() - color: string; - - @Prop() - background: string; - @Prop() selectedElement: HTMLElement; @@ -24,14 +20,22 @@ export class AppColor { private applyToAllDeck: boolean = false; - async componentDidLoad() { - await this.colorPickerListener(true); - await this.backgroundPickerListener(true); - } + @State() + private applyToText: boolean = true; // true = text, false = background + + @State() + private color: string; + + @State() + private background: string; - async componentDidUnload() { - await this.colorPickerListener(false); - await this.backgroundPickerListener(false); + @State() + private moreColors: boolean = true; + + async componentWillLoad() { + await this.initCurrentColors(this.selectedElement); + + this.moreColors = !isIPad(); } private async closePopover() { @@ -41,151 +45,145 @@ export class AppColor { private async selectApplyToAllDeck($event: CustomEvent) { if ($event) { this.applyToAllDeck = $event.detail; - } - } - - // Color - - private colorPickerListener(bind: boolean): Promise { - return new Promise((resolve) => { - const colorPicker: HTMLInputElement = this.el.querySelector('input[name=\'color-picker\']'); - if (!colorPicker) { - resolve(); - return; + if (this.deckOrSlide) { + await this.initCurrentColors(this.applyToAllDeck ? this.selectedElement.parentElement : this.selectedElement); } - - if (bind) { - colorPicker.addEventListener('change', this.selectColor, false); - } else { - colorPicker.removeEventListener('change', this.selectColor, true); - } - - - resolve(); - }); + } } - private openColorPicker(): Promise { - return new Promise((resolve) => { - const colorPicker: HTMLInputElement = this.el.querySelector('input[name=\'color-picker\']'); - - if (!colorPicker) { - resolve(); - return; - } - - colorPicker.click(); - - resolve(); - }); + private selectApplyToText($event: CustomEvent) { + if ($event && $event.detail) { + this.applyToText = $event.detail.value; + } } - private selectColor = async ($event) => { - if (!this.selectedElement) { + private async selectColor($event: CustomEvent) { + if (!this.selectedElement || !$event || !$event.detail) { return; } - this.color = $event.target.value; - - if (this.deckOrSlide) { - const element: HTMLElement = this.applyToAllDeck ? this.selectedElement.parentElement : this.selectedElement; + const selectedColor: string = $event.detail.hex; - element.style.setProperty('--color', $event.target.value); + if (this.applyToText) { + await this.selectTextColor(selectedColor); + this.color = selectedColor; } else { - this.selectedElement.style.color = $event.target.value; + await this.selectBackground(selectedColor); + this.background = selectedColor; } + } - this.colorDidChange.emit(this.applyToAllDeck); - }; - - // Background - - private backgroundPickerListener(bind: boolean): Promise { + private selectTextColor(color: string): Promise { return new Promise((resolve) => { - const backgroundPicker: HTMLInputElement = this.el.querySelector('input[name=\'background-picker\']'); - - if (!backgroundPicker) { + if (!this.selectedElement || !color) { resolve(); return; } - if (bind) { - backgroundPicker.addEventListener('change', this.selectBackground, false); + if (this.deckOrSlide) { + const element: HTMLElement = this.applyToAllDeck ? this.selectedElement.parentElement : this.selectedElement; + + element.style.setProperty('--color', color); } else { - backgroundPicker.removeEventListener('change', this.selectBackground, true); + this.selectedElement.style.color = color; } + this.colorDidChange.emit(this.applyToAllDeck); resolve(); }); } - private openBackgroundPicker(): Promise { + private selectBackground(color: string): Promise { return new Promise((resolve) => { - const backgroundPicker: HTMLInputElement = this.el.querySelector('input[name=\'background-picker\']'); - - if (!backgroundPicker) { + if (!this.selectedElement || !color) { resolve(); return; } - backgroundPicker.click(); + if (this.deckOrSlide) { + const element: HTMLElement = this.applyToAllDeck ? this.selectedElement.parentElement : this.selectedElement; + + element.style.setProperty('--background', color); + } else if (this.selectedElement.parentElement && this.selectedElement.parentElement.nodeName && this.selectedElement.parentElement.nodeName.toLowerCase() === 'deckgo-slide-split') { + const element: HTMLElement = this.selectedElement.parentElement; + + if (this.selectedElement.getAttribute('slot') === 'start') { + element.style.setProperty('--slide-split-background-start', color); + } else if (this.selectedElement.getAttribute('slot') === 'end') { + element.style.setProperty('--slide-split-background-end', color); + } else { + this.selectedElement.style.background = color; + } + } else { + this.selectedElement.style.background = color; + } + + this.colorDidChange.emit(this.applyToAllDeck); resolve(); }); } - private selectBackground = async ($event) => { - if (!this.selectedElement) { + private async initCurrentColors(element: HTMLElement) { + if (!element) { return; } - this.background = $event.target.value; + this.color = await this.rgb2hex(element.style.getPropertyValue('--color') ? element.style.getPropertyValue('--color') : element.style.color); + this.background = await this.rgb2hex(element.style.getPropertyValue('--background') ? element.style.getPropertyValue('--background') : element.style.background); + } + + // https://css-tricks.com/converting-color-spaces-in-javascript/ + private rgb2hex(rgb: string): Promise { + return new Promise((resolve) => { + if (!rgb || rgb === undefined || rgb === '' || rgb.indexOf('rgb') <= -1) { + resolve(rgb); + return; + } - if (this.deckOrSlide) { - const element: HTMLElement = this.applyToAllDeck ? this.selectedElement.parentElement : this.selectedElement; + const separator: string = rgb.indexOf(",") > -1 ? "," : " "; - element.style.setProperty('--background', $event.target.value); - } else if (this.selectedElement.parentElement && this.selectedElement.parentElement.nodeName && this.selectedElement.parentElement.nodeName.toLowerCase() === 'deckgo-slide-split') { - const element: HTMLElement = this.selectedElement.parentElement; + const rgbs: string[] = rgb.substr(4).split(")")[0].split(separator); - if (this.selectedElement.getAttribute('slot') === 'start') { - element.style.setProperty('--slide-split-background-start', $event.target.value); - } else if (this.selectedElement.getAttribute('slot') === 'end') { - element.style.setProperty('--slide-split-background-end', $event.target.value); - } else { - this.selectedElement.style.background = $event.target.value; - } - } else { - this.selectedElement.style.background = $event.target.value; - } + const r: string = (+rgbs[0]).toString(16); + const g: string = (+rgbs[1]).toString(16); + const b: string = (+rgbs[2]).toString(16); - this.colorDidChange.emit(this.applyToAllDeck); - }; + resolve(`#${r.length == 1 ? '0' + r : r}${g.length == 1 ? '0' + g : g}${b.length == 1 ? '0' + b : b}`); + }); + } render() { return [ -

    Color

    - this.closePopover()}> -
    , +

    Color

    + this.closePopover()}> + + + , - this.selectApplyToAllDeck($event)}> - - - this.openColorPicker()} color="primary"> - Text color - - - - - this.openBackgroundPicker()} color="secondary"> - Background color - - + this.selectApplyToAllDeck($event)}> + + this.selectApplyToText($event)}> + + Apply color to + + + + Text + + + + Background + + + , - , - + this.selectColor($event)} color-hex={this.applyToText ? this.color : this.background}> + + ] } diff --git a/studio/src/components.d.ts b/studio/src/components.d.ts index e691cb820..cebcdc3b3 100644 --- a/studio/src/components.d.ts +++ b/studio/src/components.d.ts @@ -32,8 +32,6 @@ export namespace Components { 'selectedElement': HTMLElement; } interface AppColor { - 'background': string; - 'color': string; 'deckOrSlide': boolean; 'selectedElement': HTMLElement; } @@ -587,8 +585,6 @@ declare namespace LocalJSX { 'selectedElement'?: HTMLElement; } interface AppColor extends JSXBase.HTMLAttributes { - 'background'?: string; - 'color'?: string; 'deckOrSlide'?: boolean; 'onColorDidChange'?: (event: CustomEvent) => void; 'selectedElement'?: HTMLElement; diff --git a/studio/src/global/app-dev.ts b/studio/src/global/app-dev.ts index 2349e57de..33caf37c6 100644 --- a/studio/src/global/app-dev.ts +++ b/studio/src/global/app-dev.ts @@ -12,6 +12,7 @@ import '@deckdeckgo/remote'; import '@deckdeckgo/qrcode'; import '@deckdeckgo/highlight-code'; import '@deckdeckgo/lazy-img'; +import '@deckdeckgo/color'; import '@deckdeckgo/slide-title'; import '@deckdeckgo/slide-content'; diff --git a/studio/src/global/app.ts b/studio/src/global/app.ts index 824e5cb75..0a2a96089 100644 --- a/studio/src/global/app.ts +++ b/studio/src/global/app.ts @@ -12,6 +12,7 @@ import '@deckdeckgo/remote'; import '@deckdeckgo/qrcode'; import '@deckdeckgo/highlight-code'; import '@deckdeckgo/lazy-img'; +import '@deckdeckgo/color'; import '@deckdeckgo/slide-title'; import '@deckdeckgo/slide-content'; diff --git a/webcomponents/color/.editorconfig b/webcomponents/color/.editorconfig new file mode 100644 index 000000000..f1cc3ad32 --- /dev/null +++ b/webcomponents/color/.editorconfig @@ -0,0 +1,15 @@ +# http://editorconfig.org + +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +insert_final_newline = false +trim_trailing_whitespace = false diff --git a/webcomponents/color/.gitignore b/webcomponents/color/.gitignore new file mode 100644 index 000000000..c3ea58a61 --- /dev/null +++ b/webcomponents/color/.gitignore @@ -0,0 +1,26 @@ +dist/ +www/ +loader/ + +*~ +*.sw[mnpcod] +*.log +*.lock +*.tmp +*.tmp.* +log.txt +*.sublime-project +*.sublime-workspace + +.stencil/ +.idea/ +.vscode/ +.sass-cache/ +.versions/ +node_modules/ +$RECYCLE.BIN/ + +.DS_Store +Thumbs.db +UserInterfaceState.xcuserstate +.env diff --git a/webcomponents/color/LICENSE b/webcomponents/color/LICENSE new file mode 100644 index 000000000..c0e5d1513 --- /dev/null +++ b/webcomponents/color/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 David Dal Busco and Nicolas Mattia + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/webcomponents/color/package-lock.json b/webcomponents/color/package-lock.json new file mode 100644 index 000000000..7a5576e16 --- /dev/null +++ b/webcomponents/color/package-lock.json @@ -0,0 +1,193 @@ +{ + "name": "@deckdeckgo/color", + "version": "0.0.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@stencil/core": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@stencil/core/-/core-1.4.0.tgz", + "integrity": "sha512-/iI87p7XsqE3U96ykx4SSY/btv9jZguI3JkG8RaTNlQipPUmPb0JmLei8sgijTUD/fY5TFuE3L1o8hwLI0rW3A==", + "dev": true, + "requires": { + "typescript": "3.6.2" + } + }, + "@stencil/postcss": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@stencil/postcss/-/postcss-1.0.1.tgz", + "integrity": "sha512-+QOLwdiMSeE6XbvjOM8bfMIX6E6L4DFLmnp0wZqCj4O/PVkNfEQA6IXZgd6F+OIfZ1wBy/dxR4Jvtwfo+QXa2g==", + "dev": true, + "requires": { + "postcss": "~7.0.17" + } + }, + "@stencil/sass": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@stencil/sass/-/sass-1.0.1.tgz", + "integrity": "sha512-3vmF8zir9FcVY/tYW0/V/pWrYSU684eASmALL2v29PGJvX6/CXh9n8LF7Jy95SpJPij3lisIUXLls7edXy2hYg==", + "dev": true + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "autoprefixer": { + "version": "9.6.1", + "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.6.1.tgz", + "integrity": "sha512-aVo5WxR3VyvyJxcJC3h4FKfwCQvQWb1tSI5VHNibddCVWrcD1NvlxEweg3TSgiPztMnWfjpy2FURKA2kvDE+Tw==", + "dev": true, + "requires": { + "browserslist": "^4.6.3", + "caniuse-lite": "^1.0.30000980", + "chalk": "^2.4.2", + "normalize-range": "^0.1.2", + "num2fraction": "^1.2.2", + "postcss": "^7.0.17", + "postcss-value-parser": "^4.0.0" + } + }, + "browserslist": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.7.0.tgz", + "integrity": "sha512-9rGNDtnj+HaahxiVV38Gn8n8Lr8REKsel68v1sPFfIGEK6uSXTY3h9acgiT1dZVtOOUtifo/Dn8daDQ5dUgVsA==", + "dev": true, + "requires": { + "caniuse-lite": "^1.0.30000989", + "electron-to-chromium": "^1.3.247", + "node-releases": "^1.1.29" + } + }, + "caniuse-lite": { + "version": "1.0.30000989", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000989.tgz", + "integrity": "sha512-vrMcvSuMz16YY6GSVZ0dWDTJP8jqk3iFQ/Aq5iqblPwxSVVZI+zxDyTX0VPqtQsDnfdrBDcsmhgTEOh5R8Lbpw==", + "dev": true + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "dependencies": { + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + }, + "electron-to-chromium": { + "version": "1.3.263", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.263.tgz", + "integrity": "sha512-VfPi+sE/1nEKOV7DWDqWSUGP7ztJG5FeqHbMEj6dBb/arKnxpOCnRXOSC6HBV6qTfK5v8CX7xWCqzN36UqG1oA==", + "dev": true + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, + "node-releases": { + "version": "1.1.32", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.32.tgz", + "integrity": "sha512-VhVknkitq8dqtWoluagsGPn3dxTvN9fwgR59fV3D7sLBHe0JfDramsMI8n8mY//ccq/Kkrf8ZRHRpsyVZ3qw1A==", + "dev": true, + "requires": { + "semver": "^5.3.0" + } + }, + "normalize-range": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/normalize-range/-/normalize-range-0.1.2.tgz", + "integrity": "sha1-LRDAa9/TEuqXd2laTShDlFa3WUI=", + "dev": true + }, + "num2fraction": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/num2fraction/-/num2fraction-1.2.2.tgz", + "integrity": "sha1-b2gragJ6Tp3fpFZM0lidHU5mnt4=", + "dev": true + }, + "postcss": { + "version": "7.0.18", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.18.tgz", + "integrity": "sha512-/7g1QXXgegpF+9GJj4iN7ChGF40sYuGYJ8WZu8DZWnmhQ/G36hfdk3q9LBJmoK+lZ+yzZ5KYpOoxq7LF1BxE8g==", + "dev": true, + "requires": { + "chalk": "^2.4.2", + "source-map": "^0.6.1", + "supports-color": "^6.1.0" + } + }, + "postcss-value-parser": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.0.2.tgz", + "integrity": "sha512-LmeoohTpp/K4UiyQCwuGWlONxXamGzCMtFxLq4W1nZVGIQLYvMCJx3yAF9qyyuFpflABI9yVdtJAqbihOsCsJQ==", + "dev": true + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + }, + "supports-color": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz", + "integrity": "sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + }, + "typescript": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.2.tgz", + "integrity": "sha512-lmQ4L+J6mnu3xweP8+rOrUwzmN+MRAj7TgtJtDaXE5PMyX2kCrklhg3rvOsOIfNeAWMQWO2F1GPc1kMD2vLAfw==", + "dev": true + } + } +} diff --git a/webcomponents/color/package.json b/webcomponents/color/package.json new file mode 100644 index 000000000..b7492a1c2 --- /dev/null +++ b/webcomponents/color/package.json @@ -0,0 +1,55 @@ +{ + "name": "@deckdeckgo/color", + "version": "0.0.1", + "description": "A color picker developed with Web Components", + "main": "dist/index.js", + "module": "dist/index.mjs", + "es2015": "dist/esm/index.mjs", + "es2017": "dist/esm/index.mjs", + "types": "dist/types/index.d.ts", + "collection": "dist/collection/collection-manifest.json", + "collection:main": "dist/collection/index.js", + "unpkg": "dist/deckdeckgo-color/deckdeckgo-color.js", + "files": [ + "dist/", + "README.md", + "loader/" + ], + "scripts": { + "build": "stencil build --docs", + "start": "stencil build --dev --watch --serve", + "test": "stencil test --spec --e2e", + "test.watch": "stencil test --spec --e2e --watchAll", + "generate": "stencil generate" + }, + "devDependencies": { + "@stencil/core": "^1.4.0", + "@stencil/postcss": "^1.0.1", + "@stencil/sass": "^1.0.1", + "autoprefixer": "^9.6.1" + }, + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/deckgo/deckdeckgo.git" + }, + "author": "David Dal Busco", + "bugs": { + "url": "https://github.com/deckgo/deckdeckgo" + }, + "homepage": "https://deckdeckgo.com", + "keywords": [ + "stencil", + "stenciljs", + "web components", + "pwa", + "progressive web app", + "presentation", + "slides", + "slideshow", + "talk", + "prismjs", + "color", + "color-picker" + ] +} diff --git a/webcomponents/color/readme.md b/webcomponents/color/readme.md new file mode 100644 index 000000000..73788dd64 --- /dev/null +++ b/webcomponents/color/readme.md @@ -0,0 +1,72 @@ +![Built With Stencil](https://img.shields.io/badge/-Built%20With%20Stencil-16161d.svg?logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE5LjIuMSwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IgoJIHZpZXdCb3g9IjAgMCA1MTIgNTEyIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1MTIgNTEyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI%2BCjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI%2BCgkuc3Qwe2ZpbGw6I0ZGRkZGRjt9Cjwvc3R5bGU%2BCjxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik00MjQuNywzNzMuOWMwLDM3LjYtNTUuMSw2OC42LTkyLjcsNjguNkgxODAuNGMtMzcuOSwwLTkyLjctMzAuNy05Mi43LTY4LjZ2LTMuNmgzMzYuOVYzNzMuOXoiLz4KPHBhdGggY2xhc3M9InN0MCIgZD0iTTQyNC43LDI5Mi4xSDE4MC40Yy0zNy42LDAtOTIuNy0zMS05Mi43LTY4LjZ2LTMuNkgzMzJjMzcuNiwwLDkyLjcsMzEsOTIuNyw2OC42VjI5Mi4xeiIvPgo8cGF0aCBjbGFzcz0ic3QwIiBkPSJNNDI0LjcsMTQxLjdIODcuN3YtMy42YzAtMzcuNiw1NC44LTY4LjYsOTIuNy02OC42SDMzMmMzNy45LDAsOTIuNywzMC43LDkyLjcsNjguNlYxNDEuN3oiLz4KPC9zdmc%2BCg%3D%3D&colorA=16161d&style=flat-square) + +# Stencil Component Starter + +This is a starter project for building a standalone Web Component using Stencil. + +Stencil is also great for building entire apps. For that, use the [stencil-app-starter](https://github.com/ionic-team/stencil-app-starter) instead. + +# Stencil + +Stencil is a compiler for building fast web apps using Web Components. + +Stencil combines the best concepts of the most popular frontend frameworks into a compile-time rather than run-time tool. Stencil takes TypeScript, JSX, a tiny virtual DOM layer, efficient one-way data binding, an asynchronous rendering pipeline (similar to React Fiber), and lazy-loading out of the box, and generates 100% standards-based Web Components that run in any browser supporting the Custom Elements v1 spec. + +Stencil components are just Web Components, so they work in any major framework or with no framework at all. + +## Getting Started + +To start building a new web component using Stencil, clone this repo to a new directory: + +```bash +git clone https://github.com/ionic-team/stencil-component-starter.git my-component +cd my-component +git remote rm origin +``` + +and run: + +```bash +npm install +npm start +``` + +To build the component for production, run: + +```bash +npm run build +``` + +To run the unit tests for the components, run: + +```bash +npm test +``` + +Need help? Check out our docs [here](https://stenciljs.com/docs/my-first-component). + + +## Naming Components + +When creating new component tags, we recommend _not_ using `stencil` in the component name (ex: ``). This is because the generated component has little to nothing to do with Stencil; it's just a web component! + +Instead, use a prefix that fits your company or any name for a group of related components. For example, all of the Ionic generated web components use the prefix `ion`. + + +## Using this component + +### Script tag + +- [Publish to NPM](https://docs.npmjs.com/getting-started/publishing-npm-packages) +- Put a script tag similar to this `` in the head of your index.html +- Then you can use the element anywhere in your template, JSX, html etc + +### Node Modules +- Run `npm install my-component --save` +- Put a script tag similar to this `` in the head of your index.html +- Then you can use the element anywhere in your template, JSX, html etc + +### In a stencil-starter app +- Run `npm install my-component --save` +- Add an import to the npm packages `import my-component;` +- Then you can use the element anywhere in your template, JSX, html etc diff --git a/webcomponents/color/src/components.d.ts b/webcomponents/color/src/components.d.ts new file mode 100644 index 000000000..e3caf3779 --- /dev/null +++ b/webcomponents/color/src/components.d.ts @@ -0,0 +1,59 @@ +/* tslint:disable */ +/** + * This is an autogenerated file created by the Stencil compiler. + * It contains typing information for all components that exist in this project. + */ + + +import { HTMLStencilElement, JSXBase } from '@stencil/core/internal'; +import { + DeckdeckgoPalette, + DeckdeckgoPaletteColor, +} from './components/utils/deckdeckgo-palette'; + +export namespace Components { + interface DeckgoColor { + 'colorHex': string; + 'more': boolean; + 'moreAlt': string; + 'palette': DeckdeckgoPalette[]; + } +} + +declare global { + + + interface HTMLDeckgoColorElement extends Components.DeckgoColor, HTMLStencilElement {} + var HTMLDeckgoColorElement: { + prototype: HTMLDeckgoColorElement; + new (): HTMLDeckgoColorElement; + }; + interface HTMLElementTagNameMap { + 'deckgo-color': HTMLDeckgoColorElement; + } +} + +declare namespace LocalJSX { + interface DeckgoColor extends JSXBase.HTMLAttributes { + 'colorHex'?: string; + 'more'?: boolean; + 'moreAlt'?: string; + 'onColorChange'?: (event: CustomEvent) => void; + 'palette'?: DeckdeckgoPalette[]; + } + + interface IntrinsicElements { + 'deckgo-color': DeckgoColor; + } +} + +export { LocalJSX as JSX }; + + +declare module "@stencil/core" { + export namespace JSX { + interface IntrinsicElements extends LocalJSX.IntrinsicElements {} + } +} + + diff --git a/webcomponents/color/src/components/color/deckdeckgo-color.scss b/webcomponents/color/src/components/color/deckdeckgo-color.scss new file mode 100644 index 000000000..f16b7a337 --- /dev/null +++ b/webcomponents/color/src/components/color/deckdeckgo-color.scss @@ -0,0 +1,69 @@ +:host { + display: block; +} + +div.color-container { + position: relative; + + display: flex; + align-items: center; + flex-wrap: wrap; + + button, div.more { + width: var(--deckgo-button-width, 28px); + height: var(--deckgo-button-height, 28px); + + margin: var(--deckgo-button-margin, 4px); + padding: 0; + + outline: var(--deckgo-button-outline, none); + border: var(--deckgo-button-border, none); + } + + button { + + cursor: pointer; + + border-radius: var(--deckgo-button-border-radius, 50%); + + background: var(--deckdeckgo-palette-color-hex); + + &.selected { + box-shadow: 0 0 8px 4px rgba(var(--deckdeckgo-palette-color-rgb), 0.4); + } + + &:not(.selected):hover { + box-shadow: 0 0 8px 2px rgba(var(--deckdeckgo-palette-color-rgb), 0.4); + } + } + + div.more { + display: inline-block; + position: relative; + + overflow: hidden; + + button, input { + position: absolute; + } + + button { + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + + margin: 0; + + border-radius: var(--deckgo-button-more-border-radius); + border: var(--deckgo-button-more-border); + } + + input { + bottom: 0; + right: 0; + + transform: translate(100%, 100%); + } + } + +} diff --git a/webcomponents/color/src/components/color/deckdeckgo-color.tsx b/webcomponents/color/src/components/color/deckdeckgo-color.tsx new file mode 100644 index 000000000..912336190 --- /dev/null +++ b/webcomponents/color/src/components/color/deckdeckgo-color.tsx @@ -0,0 +1,161 @@ +import {Component, h, Prop, EventEmitter, Event, Element, Host} from '@stencil/core'; + +import {DeckdeckgoPalette, DeckdeckgoPaletteColor, DEFAULT_PALETTE} from '../utils/deckdeckgo-palette'; + +@Component({ + tag: 'deckgo-color', + styleUrl: 'deckdeckgo-color.scss', + shadow: true +}) +export class DeckdeckgoColor { + + @Element() el: HTMLElement; + + @Prop({mutable: true}) palette: DeckdeckgoPalette[] = DEFAULT_PALETTE; + + @Prop() more: boolean = true; + @Prop() moreAlt: string = 'More'; + + @Prop({mutable: true}) colorHex: string; + + @Event() + colorChange: EventEmitter; + + async componentDidLoad() { + await this.colorPickerListener(true); + } + + async componentDidUnload() { + await this.colorPickerListener(false); + } + + private pickColor(paletteColor: DeckdeckgoPalette): Promise { + return new Promise((resolve) => { + if (!this.palette || this.palette.length <= 0) { + resolve(); + return; + } + + this.colorHex = paletteColor.color ? paletteColor.color.hex : undefined; + + this.colorChange.emit(paletteColor.color); + + resolve(); + }); + } + + private openColorPicker(): Promise { + return new Promise(async (resolve) => { + const colorPicker: HTMLInputElement = this.el.shadowRoot.querySelector('input[name=\'color-picker\']'); + + if (!colorPicker) { + resolve(); + return; + } + + colorPicker.click(); + + resolve(); + }); + } + + private colorPickerListener(bind: boolean): Promise { + return new Promise((resolve) => { + const colorPicker: HTMLInputElement = this.el.shadowRoot.querySelector('input[name=\'color-picker\']'); + + if (!colorPicker) { + resolve(); + return; + } + + if (bind) { + colorPicker.addEventListener('change', this.selectColor, false); + } else { + colorPicker.removeEventListener('change', this.selectColor, true); + } + + resolve(); + }); + } + + private selectColor = async ($event) => { + const selectedColor: string = $event.target.value; + + this.colorHex = undefined; + + this.colorChange.emit({ + hex: selectedColor, + rgb: await this.hexToRgb(selectedColor) + }); + }; + + // https://stackoverflow.com/a/5624139/5404186 + private hexToRgb(hex: string): Promise { + return new Promise((resolve) => { + if (!hex || hex === undefined || hex === '') { + resolve(undefined); + return; + } + + const result: RegExpExecArray | null = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); + + resolve(result ? `${parseInt(result[1], 16)}, ${parseInt(result[2], 16)}, ${parseInt(result[3], 16)}` : undefined); + }); + } + + private isHexColorSelected(element: DeckdeckgoPalette): boolean { + if (!element || !element.color || !element.color.hex) { + return false; + } + + if (!this.colorHex) { + return false; + } + + return this.colorHex.toUpperCase() === element.color.hex.toUpperCase(); + } + + render() { + return +
    + {this.renderPalette()} + {this.renderMore()} +
    +
    ; + } + + private renderPalette() { + if (this.palette && this.palette.length > 0) { + return ( + this.palette.map((element: DeckdeckgoPalette) => { + + let style = { + '--deckdeckgo-palette-color-hex': `${element.color.hex}`, + '--deckdeckgo-palette-color-rgb': `${element.color.rgb}` + }; + + return + }) + ); + } else { + return undefined; + } + } + + private renderMore() { + if (this.more) { + return
    + + +
    + } else { + return undefined; + } + } +} diff --git a/webcomponents/color/src/components/color/readme.md b/webcomponents/color/src/components/color/readme.md new file mode 100644 index 000000000..a60b33249 --- /dev/null +++ b/webcomponents/color/src/components/color/readme.md @@ -0,0 +1,27 @@ +# my-component + + + + + + +## Properties + +| Property | Attribute | Description | Type | Default | +| ---------- | ----------- | ----------- | --------------------- | ----------------- | +| `colorHex` | `color-hex` | | `string` | `undefined` | +| `more` | `more` | | `boolean` | `true` | +| `moreAlt` | `more-alt` | | `string` | `'More'` | +| `palette` | -- | | `DeckdeckgoPalette[]` | `DEFAULT_PALETTE` | + + +## Events + +| Event | Description | Type | +| ------------- | ----------- | ------------------------------------- | +| `colorChange` | | `CustomEvent` | + + +---------------------------------------------- + +*Built with [StencilJS](https://stenciljs.com/)* diff --git a/webcomponents/color/src/components/utils/deckdeckgo-palette.tsx b/webcomponents/color/src/components/utils/deckdeckgo-palette.tsx new file mode 100644 index 000000000..6a8515418 --- /dev/null +++ b/webcomponents/color/src/components/utils/deckdeckgo-palette.tsx @@ -0,0 +1,89 @@ +export interface DeckdeckgoPaletteColor { + hex: string; + rgb?: string; +} + +export interface DeckdeckgoPalette { + color: DeckdeckgoPaletteColor; + alt?: string; +} + +export const DEFAULT_PALETTE: DeckdeckgoPalette[] = [ + { + color: { + hex: '#FF6900', + rgb: '255,105,0' + }, + alt: 'Orange' + }, + { + color: { + hex: '#FCB900', + rgb: '252,185,0' + }, + alt: 'Yellow' + }, + { + color: { + hex: '#7BDCB5', + rgb: '123,220,181' + }, + alt: 'Light green' + }, + { + color: { + hex: '#00D084', + rgb: '0,208,132' + }, + alt: 'Green' + }, + { + color: { + hex: '#8ED1FC', + rgb: '142,209,252' + }, + alt: 'Light blue' + }, + { + color: { + hex: '#0693E3', + rgb: '6,147,227' + }, + alt: 'Blue' + }, + { + color: { + hex: '#ABB8C3', + rgb: '171,184,195' + }, + alt: 'Grey' + }, + { + color: { + hex: '#EB144C', + rgb: '235,20,76' + }, + alt: 'Red' + }, + { + color: { + hex: '#F78DA7', + rgb: '247,141,167' + }, + alt: 'Pink' + }, + { + color: { + hex: '#9900EF', + rgb: '153,0,239' + }, + alt: 'Violet' + }, + { + color: { + hex: '#000000', + rgb: '0,0,0' + }, + alt: 'Black' + } +]; diff --git a/webcomponents/color/src/index.html b/webcomponents/color/src/index.html new file mode 100644 index 000000000..91b7094fa --- /dev/null +++ b/webcomponents/color/src/index.html @@ -0,0 +1,20 @@ + + + + + + DeckDeckGo - Color + + + + + + + +
    + + ... + +
    + + diff --git a/webcomponents/color/src/index.ts b/webcomponents/color/src/index.ts new file mode 100644 index 000000000..07635cbbc --- /dev/null +++ b/webcomponents/color/src/index.ts @@ -0,0 +1 @@ +export * from './components'; diff --git a/webcomponents/color/stencil.config.ts b/webcomponents/color/stencil.config.ts new file mode 100644 index 000000000..7f35bb3d4 --- /dev/null +++ b/webcomponents/color/stencil.config.ts @@ -0,0 +1,28 @@ +import { Config } from '@stencil/core'; + +import { sass } from '@stencil/sass'; +import { postcss } from '@stencil/postcss'; +import autoprefixer from 'autoprefixer'; + +export const config: Config = { + namespace: 'deckdeckgo-color', + outputTargets: [ + { + type: 'dist', + esmLoaderPath: '../loader' + }, + { + type: 'docs-readme' + }, + { + type: 'www', + serviceWorker: null // disable service workers + } + ], + plugins: [ + sass(), + postcss({ + plugins: [autoprefixer()] + }) + ] +}; diff --git a/webcomponents/color/tsconfig.json b/webcomponents/color/tsconfig.json new file mode 100644 index 000000000..751e368d3 --- /dev/null +++ b/webcomponents/color/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "allowUnreachableCode": false, + "declaration": false, + "experimentalDecorators": true, + "lib": [ + "dom", + "es2017" + ], + "moduleResolution": "node", + "module": "esnext", + "target": "es2017", + "noUnusedLocals": true, + "noUnusedParameters": true, + "jsx": "react", + "jsxFactory": "h" + }, + "include": [ + "src", + "types/jsx.d.ts" + ], + "exclude": [ + "node_modules" + ] +} diff --git a/webcomponents/inline-editor/package-lock.json b/webcomponents/inline-editor/package-lock.json index d1963f826..62036598e 100644 --- a/webcomponents/inline-editor/package-lock.json +++ b/webcomponents/inline-editor/package-lock.json @@ -4,6 +4,173 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@deckdeckgo/color": { + "version": "file:../color", + "dependencies": { + "@stencil/core": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@stencil/core/-/core-1.4.0.tgz", + "integrity": "sha512-/iI87p7XsqE3U96ykx4SSY/btv9jZguI3JkG8RaTNlQipPUmPb0JmLei8sgijTUD/fY5TFuE3L1o8hwLI0rW3A==", + "requires": { + "typescript": "3.6.2" + } + }, + "@stencil/postcss": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@stencil/postcss/-/postcss-1.0.1.tgz", + "integrity": "sha512-+QOLwdiMSeE6XbvjOM8bfMIX6E6L4DFLmnp0wZqCj4O/PVkNfEQA6IXZgd6F+OIfZ1wBy/dxR4Jvtwfo+QXa2g==", + "requires": { + "postcss": "~7.0.17" + } + }, + "@stencil/sass": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@stencil/sass/-/sass-1.0.1.tgz", + "integrity": "sha512-3vmF8zir9FcVY/tYW0/V/pWrYSU684eASmALL2v29PGJvX6/CXh9n8LF7Jy95SpJPij3lisIUXLls7edXy2hYg==" + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "requires": { + "color-convert": "^1.9.0" + } + }, + "autoprefixer": { + "version": "9.6.1", + "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.6.1.tgz", + "integrity": "sha512-aVo5WxR3VyvyJxcJC3h4FKfwCQvQWb1tSI5VHNibddCVWrcD1NvlxEweg3TSgiPztMnWfjpy2FURKA2kvDE+Tw==", + "requires": { + "browserslist": "^4.6.3", + "caniuse-lite": "^1.0.30000980", + "chalk": "^2.4.2", + "normalize-range": "^0.1.2", + "num2fraction": "^1.2.2", + "postcss": "^7.0.17", + "postcss-value-parser": "^4.0.0" + } + }, + "browserslist": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.7.0.tgz", + "integrity": "sha512-9rGNDtnj+HaahxiVV38Gn8n8Lr8REKsel68v1sPFfIGEK6uSXTY3h9acgiT1dZVtOOUtifo/Dn8daDQ5dUgVsA==", + "requires": { + "caniuse-lite": "^1.0.30000989", + "electron-to-chromium": "^1.3.247", + "node-releases": "^1.1.29" + } + }, + "caniuse-lite": { + "version": "1.0.30000989", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000989.tgz", + "integrity": "sha512-vrMcvSuMz16YY6GSVZ0dWDTJP8jqk3iFQ/Aq5iqblPwxSVVZI+zxDyTX0VPqtQsDnfdrBDcsmhgTEOh5R8Lbpw==" + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "dependencies": { + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + }, + "electron-to-chromium": { + "version": "1.3.263", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.263.tgz", + "integrity": "sha512-VfPi+sE/1nEKOV7DWDqWSUGP7ztJG5FeqHbMEj6dBb/arKnxpOCnRXOSC6HBV6qTfK5v8CX7xWCqzN36UqG1oA==" + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" + }, + "node-releases": { + "version": "1.1.32", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.32.tgz", + "integrity": "sha512-VhVknkitq8dqtWoluagsGPn3dxTvN9fwgR59fV3D7sLBHe0JfDramsMI8n8mY//ccq/Kkrf8ZRHRpsyVZ3qw1A==", + "requires": { + "semver": "^5.3.0" + } + }, + "normalize-range": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/normalize-range/-/normalize-range-0.1.2.tgz", + "integrity": "sha1-LRDAa9/TEuqXd2laTShDlFa3WUI=" + }, + "num2fraction": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/num2fraction/-/num2fraction-1.2.2.tgz", + "integrity": "sha1-b2gragJ6Tp3fpFZM0lidHU5mnt4=" + }, + "postcss": { + "version": "7.0.18", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.18.tgz", + "integrity": "sha512-/7g1QXXgegpF+9GJj4iN7ChGF40sYuGYJ8WZu8DZWnmhQ/G36hfdk3q9LBJmoK+lZ+yzZ5KYpOoxq7LF1BxE8g==", + "requires": { + "chalk": "^2.4.2", + "source-map": "^0.6.1", + "supports-color": "^6.1.0" + } + }, + "postcss-value-parser": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.0.2.tgz", + "integrity": "sha512-LmeoohTpp/K4UiyQCwuGWlONxXamGzCMtFxLq4W1nZVGIQLYvMCJx3yAF9qyyuFpflABI9yVdtJAqbihOsCsJQ==" + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + }, + "supports-color": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz", + "integrity": "sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==", + "requires": { + "has-flag": "^3.0.0" + } + }, + "typescript": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.2.tgz", + "integrity": "sha512-lmQ4L+J6mnu3xweP8+rOrUwzmN+MRAj7TgtJtDaXE5PMyX2kCrklhg3rvOsOIfNeAWMQWO2F1GPc1kMD2vLAfw==" + } + } + }, "@deckdeckgo/utils": { "version": "1.0.0-rc.1-1", "resolved": "https://registry.npmjs.org/@deckdeckgo/utils/-/utils-1.0.0-rc.1-1.tgz", diff --git a/webcomponents/inline-editor/package.json b/webcomponents/inline-editor/package.json index a177cc417..68cac19eb 100644 --- a/webcomponents/inline-editor/package.json +++ b/webcomponents/inline-editor/package.json @@ -22,6 +22,7 @@ "test.watch": "stencil test --spec --e2e --watchAll" }, "dependencies": { + "@deckdeckgo/color": "file:../color", "@deckdeckgo/utils": "^1.0.0-rc.1-1" }, "devDependencies": { diff --git a/webcomponents/inline-editor/src/components/inline-editor/deckdeckgo-inline-editor.scss b/webcomponents/inline-editor/src/components/inline-editor/deckdeckgo-inline-editor.scss index 6b4796146..51c29b53d 100644 --- a/webcomponents/inline-editor/src/components/inline-editor/deckdeckgo-inline-editor.scss +++ b/webcomponents/inline-editor/src/components/inline-editor/deckdeckgo-inline-editor.scss @@ -106,14 +106,8 @@ div.deckgo-tools { } } - input[name="color-picker"] { - position: absolute; - left: 144px; - visibility: hidden; - } - div.link { - width: 100%; + width: var(--deckgo-inline-editor-width, 216px); height: 44px; line-height: 44px; @@ -137,6 +131,14 @@ div.deckgo-tools { } } + div.color { + max-width: var(--deckgo-inline-editor-width, 216px); + + deckgo-color { + pointer-events: all; + } + } + &.deckgo-tools-activated { visibility: visible; opacity: 1; diff --git a/webcomponents/inline-editor/src/components/inline-editor/deckdeckgo-inline-editor.tsx b/webcomponents/inline-editor/src/components/inline-editor/deckdeckgo-inline-editor.tsx index da5471a3b..cf2cba780 100644 --- a/webcomponents/inline-editor/src/components/inline-editor/deckdeckgo-inline-editor.tsx +++ b/webcomponents/inline-editor/src/components/inline-editor/deckdeckgo-inline-editor.tsx @@ -2,6 +2,8 @@ import {Component, Element, EventEmitter, Listen, Prop, State, Watch, Event, Met import {isMobile, isIOS, unifyEvent, debounce} from '@deckdeckgo/utils'; +import '@deckdeckgo/color'; + import {DeckdeckgoInlineEditorUtils} from '../../types/inline-editor/deckdeckgo-inline-editor-utils'; interface AnchorLink { @@ -16,7 +18,8 @@ interface InputTargetEvent extends EventTarget { enum ToolbarActions { SELECTION, LINK, - IMAGE + IMAGE, + COLOR } enum ImageSize { @@ -141,16 +144,12 @@ export class DeckdeckgoInlineEditor { } async componentDidLoad() { - await this.colorPickerListener(true); - if (!this.mobile) { this.mobile = isMobile(); } } async componentDidUnload() { - await this.colorPickerListener(false); - await this.detachListener(this.attachTo ? this.attachTo : document); } @@ -271,6 +270,7 @@ export class DeckdeckgoInlineEditor { } this.toolbarActions = ToolbarActions.IMAGE; + this.color = undefined; await this.setToolsActivated(true); resolve(); @@ -883,34 +883,14 @@ export class DeckdeckgoInlineEditor { }); } - // Color picker - - private colorPickerListener(bind: boolean): Promise { - return new Promise((resolve) => { - const colorPicker: HTMLInputElement = this.el.shadowRoot.querySelector('input[name=\'color-picker\']'); - - if (!colorPicker) { - resolve(); - return; - } - - if (bind) { - colorPicker.addEventListener('change', this.selectColor, false); - } else { - colorPicker.removeEventListener('change', this.selectColor, true); - } - - resolve(); - }); - } - private selectColor = async ($event) => { - if (!this.selection) { + private async selectColor($event: CustomEvent) { + if (!this.selection || !$event || !$event.detail) { return; } - this.color = $event.target.value; + this.color = $event.detail.hex; if (!this.selection || this.selection.rangeCount <= 0 || !document) { return; @@ -923,20 +903,13 @@ export class DeckdeckgoInlineEditor { } document.execCommand('foreColor', false, this.color); - }; + + await this.reset(true); + } private openColorPicker(): Promise { return new Promise(async (resolve) => { - const colorPicker: HTMLInputElement = this.el.shadowRoot.querySelector('input[name=\'color-picker\']'); - - if (!colorPicker) { - resolve(); - return; - } - - colorPicker.click(); - - await this.setToolsActivated(false); + this.toolbarActions = ToolbarActions.COLOR; resolve(); }); @@ -1045,7 +1018,6 @@ export class DeckdeckgoInlineEditor { return
    {this.renderActions()} -
    ; } @@ -1059,6 +1031,12 @@ export class DeckdeckgoInlineEditor { > ); + } else if (this.toolbarActions === ToolbarActions.COLOR) { + return
    + this.selectColor($event)} more={false}> +
    +
    +
    } else if (this.toolbarActions === ToolbarActions.IMAGE) { return this.renderImageActions(); } else { diff --git a/webcomponents/inline-editor/src/components/inline-editor/readme.md b/webcomponents/inline-editor/src/components/inline-editor/readme.md index d6b7dee0c..a84480604 100644 --- a/webcomponents/inline-editor/src/components/inline-editor/readme.md +++ b/webcomponents/inline-editor/src/components/inline-editor/readme.md @@ -43,6 +43,19 @@ Type: `Promise` +## Dependencies + +### Depends on + +- deckgo-color + +### Graph +```mermaid +graph TD; + deckgo-inline-editor --> deckgo-color + style deckgo-inline-editor fill:#f9f,stroke:#333,stroke-width:4px +``` + ---------------------------------------------- *Built with [StencilJS](https://stenciljs.com/)* diff --git a/webcomponents/utils/CHANGELOG.md b/webcomponents/utils/CHANGELOG.md index 83378ef9b..a9f5dab48 100644 --- a/webcomponents/utils/CHANGELOG.md +++ b/webcomponents/utils/CHANGELOG.md @@ -1,7 +1,16 @@ + +# 1.0.0-rc.1-2 (2019-09-21) + +### Features + +* add `isIPad()` function + # 1.0.0-rc.1-1 (2019-09-01) -* improvate `debounce` typing +### Features + +* improve `debounce` typing # 1.0.0-rc.1 (2019-08-30) diff --git a/webcomponents/utils/package-lock.json b/webcomponents/utils/package-lock.json index 614b1cc53..cf25e863f 100644 --- a/webcomponents/utils/package-lock.json +++ b/webcomponents/utils/package-lock.json @@ -1,6 +1,6 @@ { "name": "@deckdeckgo/utils", - "version": "1.0.0-rc.1-1", + "version": "1.0.0-rc.1-2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/webcomponents/utils/package.json b/webcomponents/utils/package.json index 353357094..4f8c7cad9 100644 --- a/webcomponents/utils/package.json +++ b/webcomponents/utils/package.json @@ -1,6 +1,6 @@ { "name": "@deckdeckgo/utils", - "version": "1.0.0-rc.1-1", + "version": "1.0.0-rc.1-2", "author": "David Dal Busco", "description": "A collection of utils methods and functions developed for DeckDeckGo", "license": "MIT", diff --git a/webcomponents/utils/src/utils/deckdeckgo-utils.ts b/webcomponents/utils/src/utils/deckdeckgo-utils.ts index 45d69b3b1..1ada126ed 100644 --- a/webcomponents/utils/src/utils/deckdeckgo-utils.ts +++ b/webcomponents/utils/src/utils/deckdeckgo-utils.ts @@ -37,6 +37,17 @@ export function isIOS(): boolean { return /iPad|iPhone|iPod/i.test(a); } + +export function isIPad(): boolean { + if (!window || !navigator) { + return false; + } + + const a: string = navigator.userAgent || navigator.vendor || (window as any).opera; + + return /iPad/i.test(a); +} + export function isFullscreen(): boolean { if (!window || !screen) { return false;