From 04f4da89a2c6d782c730500ac524f10ed5cea7b1 Mon Sep 17 00:00:00 2001 From: FatBat Date: Mon, 30 Nov 2020 08:48:52 -0800 Subject: [PATCH 1/2] Adds support for image as confettis. --- README.md | 1 + demo-src/app.js | 65 ++++++++++++++++++++++++++++++++++++++++--------- demo/btc.svg | 1 + demo/cash.svg | 1 + index.d.ts | 1 + 5 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 demo/btc.svg create mode 100644 demo/cash.svg diff --git a/README.md b/README.md index 95b4099..06a4854 100644 --- a/README.md +++ b/README.md @@ -41,5 +41,6 @@ Optional. Configuration object to control the characteristics of the confetti: - `stagger` - Delay for each fetti in milliseconds, defaults to 0. - `random` - Randomization function, defaults to Math.random - `colors` - An array of color codes, defaults to `['#a864fd', '#29cdff', '#78ff44', '#ff718d' '#fdff6a']` +- `image` - Replace colors with an image instead (absolute or relative url). License MIT, copyright [Daniel Lundin](https://www.twitter.com/daniel-lundin) 2017 diff --git a/demo-src/app.js b/demo-src/app.js index 4f7f4c2..3b18e50 100644 --- a/demo-src/app.js +++ b/demo-src/app.js @@ -25,6 +25,11 @@ const colorPresets = [ ["#f00", "#0f0", "#00f"] ]; +const imagePresets = [ + "./btc.svg", + "./cash.svg" +]; + export default class App extends Component { constructor(props) { super(props); @@ -41,7 +46,8 @@ export default class App extends Component { }), {} ), - colorPreset: 0 + colorPreset: 0, + imagePreset: "" }; } @@ -81,12 +87,28 @@ export default class App extends Component { } render() { - const { settings, colorPreset, isLoading } = this.state; + const { settings, colorPreset, imagePreset, isLoading } = this.state; const colors = settings["colors"]; const allSettings = Object.assign({}, settings, { - colors: colorPresets[colorPreset] + colors: colorPresets[colorPreset], + image: (imagePreset !== "" && imagePresets[imagePreset]) || "" }); const settingSliders = this.renderSettingSliders(); + const imageStyle = { + label: { + "display": "flex", + "align-items": "center" + }, + radio: { + "margin-bottom": 0 + }, + img: { + "width": settings.width, + "height": settings.height, + "margin-left": "8px", + "margin-right": "8px" + } + }; return (
@@ -99,8 +121,8 @@ export default class App extends Component { this.setState({ colorPreset: 0 })} + checked={imagePreset === "" && colorPreset === 0} + onChange={() => this.setState({ colorPreset: 0, imagePreset: "" })} /> Celebration @@ -108,8 +130,8 @@ export default class App extends Component { this.setState({ colorPreset: 1 })} + checked={imagePreset === "" && colorPreset === 1} + onChange={() => this.setState({ colorPreset: 1, imagePreset: "" })} /> Monochrome @@ -117,8 +139,8 @@ export default class App extends Component { this.setState({ colorPreset: 2 })} + checked={imagePreset === "" && colorPreset === 2} + onChange={() => this.setState({ colorPreset: 2, imagePreset: "" })} /> Poker @@ -126,11 +148,32 @@ export default class App extends Component { this.setState({ colorPreset: 3 })} + checked={imagePreset === "" && colorPreset === 3} + onChange={() => this.setState({ colorPreset: 3, imagePreset: "" })} /> RGB + Image presets + +
diff --git a/demo/btc.svg b/demo/btc.svg new file mode 100644 index 0000000..9bcb725 --- /dev/null +++ b/demo/btc.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/demo/cash.svg b/demo/cash.svg new file mode 100644 index 0000000..9772ab0 --- /dev/null +++ b/demo/cash.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 874a2c0..00c57f5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -12,6 +12,7 @@ interface ConfettiConfig { elementCount?: number; decay?: number; colors?: string[]; + image?: string[]; random?: () => number; } From d6af55bf9a941a591805d1cfc7e668ff6b91c522 Mon Sep 17 00:00:00 2001 From: FatBat Date: Tue, 19 Jan 2021 17:06:15 -0800 Subject: [PATCH 2/2] Fixed image type. --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 00c57f5..52fb219 100644 --- a/index.d.ts +++ b/index.d.ts @@ -12,7 +12,7 @@ interface ConfettiConfig { elementCount?: number; decay?: number; colors?: string[]; - image?: string[]; + image?: string; random?: () => number; }