Skip to content

Feature/blocks-new-theming #33

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

Merged
merged 13 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,704 changes: 1,102 additions & 3,602 deletions examples/angular-uploader/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/angular-uploader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/platform-browser": "17.0.9",
"@angular/platform-browser-dynamic": "17.0.9",
"@angular/router": "17.0.9",
"@uploadcare/blocks": "0.39.0",
"@uploadcare/blocks": "0.44.0",
"rxjs": "7.4.0",
"tslib": "2.3.1",
"zone.js": "0.14.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
Available options: https://uploadcare.com/docs/file-uploader/options/

Also note: Some options currently are not available via `lr-config`,
but may be set via CSS properties. E.g. `darkmode`.
but may be set via CSS properties or CSS classes. E.g. accent colors or darkmode

Here they are: https://github.com/uploadcare/blocks/blob/main/blocks/themes/lr-basic/config.css
Here they are: https://uploadcare.com/docs/file-uploader/styling/
-->
<lr-config
#config
Expand All @@ -25,7 +25,8 @@
<lr-file-uploader-regular
[attr.ctx-name]="uploaderCtxName"
[class]="uploaderClassName"
[class.dark-mode-enabled]="theme === 'dark'"
[class.uc-dark]="theme === 'dark'"
[class.uc-light]="theme === 'light'"
></lr-file-uploader-regular>

<lr-upload-ctx-provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@
}

/*
Note: We set this class manually when we want File Uploader to join the dark side.
The main option here is `darkmore`. The rest ones are used to tune the theme to match the website.
CSS variables are used to customize the appearance of the file uploader.

See more: https://uploadcare.com/docs/file-uploader/styling/#base-values
See more: https://uploadcare.com/docs/file-uploader/styling/
*/
.dark-mode-enabled {
--darkmode: 1;

--h-accent: 33.3;
--s-accent: 100%;
--l-accent: 60.78%;

--clr-btn-bgr-primary: var(--ui-action-button-background);
--clr-btn-txt-primary: var(--ui-action-button-text-color);
.file-uploader {
--uc-primary-dark: var(--ui-action-button-background);
--uc-primary-foreground-dark: var(--ui-action-button-text-color);
}

.preview {
Expand Down
1 change: 0 additions & 1 deletion examples/composition/index.html

This file was deleted.

24 changes: 0 additions & 24 deletions examples/composition/src/custom-source/CustomFileUploader.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions examples/js-custom-tab/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="./src/main.js"></script>
<lr-config ctx-name="my-uploader" pubkey="a6ca334c3520777c0045" source-list="unsplash"></lr-config>
<lr-custom-file-uploader ctx-name="my-uploader" class="uc-light"></lr-custom-file-uploader>
</body>
</html>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"vite": "4.5.2"
},
"dependencies": {
"@uploadcare/blocks": "0.30.5"
"@uploadcare/blocks": "0.44.0"
}
}
23 changes: 23 additions & 0 deletions examples/js-custom-tab/src/CustomFileUploader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { FileUploaderRegular } from "@uploadcare/blocks";

export class CustomFileUploader extends FileUploaderRegular {}
CustomFileUploader.template = /* HTML */ `
<lr-simple-btn></lr-simple-btn>

<lr-modal strokes block-body-scrolling>
<lr-start-from>
<lr-drop-area with-icon clickable></lr-drop-area>
<lr-source-list wrap></lr-source-list>
<lr-copyright></lr-copyright>
</lr-start-from>
<lr-upload-list></lr-upload-list>
<lr-camera-source></lr-camera-source>
<lr-url-source></lr-url-source>
<lr-external-source></lr-external-source>
<lr-cloud-image-editor-activity></lr-cloud-image-editor-activity>
<lr-unsplash-source token="${import.meta.env.VITE_UNSPLASH_TOKEN}"></lr-unsplash-source>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider handling environment variables more cautiously in templates.

Direct usage of import.meta.env.VITE_UNSPLASH_TOKEN in the template might cause issues if the environment variable is not set, as this might happen at build time. Consider adding checks or fallbacks.

</lr-modal>

<lr-message-box></lr-message-box>
<lr-progress-bar-common></lr-progress-bar-common>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const getRandomImages = async (token) => {

export class UnsplashSource extends UploaderBlock {
activityType = "unsplash";
_currentItemId = null
_currentItemId = null;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well-implemented class with robust functionality.

The UnsplashSource class is well-implemented with proper use of asynchronous operations and event handling. However, consider reviewing direct DOM manipulations in event handlers, as these might conflict with frameworks that use a virtual DOM.

Also applies to: 32-40, 58-61, 76-76, 99-111, 158-160


init$ = {
handleNext: () => {
Expand All @@ -28,21 +28,16 @@ export class UnsplashSource extends UploaderBlock {
},
};

cssInit$ = {
"--cfg-unsplash-token": null,
};

get token() {
return this.getCssData("--cfg-unsplash-token");
}

async fetch() {
const items = await getRandomImages(this.token);
const items = await getRandomImages(this.$.token);
this._items.push(...items);
for (const item of items) {
this._splide.add(
/* HTML */ `<li data-id="${item.id}" class="splide__slide"><img src="${item.url}" /></li>`
);
this._splide.add(/* HTML */ `<li
data-id="${item.id}"
class="splide__slide"
>
<img src="${item.url}" />
</li>`);
}
}

Expand All @@ -60,10 +55,10 @@ export class UnsplashSource extends UploaderBlock {
this._items.shift();
});

this._splide.on("active", ({slide}) => {
this._splide.on("active", ({ slide }) => {
const itemId = slide.dataset.id;
this._currentItemId = itemId;
})
});
}

unmount() {
Expand All @@ -78,7 +73,7 @@ export class UnsplashSource extends UploaderBlock {
}

pick() {
const item = this._items.find(item => item.id === this._currentItemId)
const item = this._items.find((item) => item.id === this._currentItemId);

this.uploadCollection.add({
externalUrl: item.rawUrl,
Expand All @@ -101,6 +96,19 @@ export class UnsplashSource extends UploaderBlock {
}

static template = /* HTML */ `
<svg width="0" height="0" style="position:absolute">
<symbol
viewBox="0 0 24 24"
id="uc-icon-unsplash"
xmlns="http://www.w3.org/2000/svg"
>
<path
fill="currentColor"
fill-rule="evenodd"
d="M15 4.5H9v4h6v-4ZM4 10.5h5v4h6v-4h5v9H4v-9Z"
/>
</symbol>
</svg>
<lr-activity-header>
<button
type="button"
Expand Down Expand Up @@ -146,3 +154,7 @@ export class UnsplashSource extends UploaderBlock {
</div>
`;
}

UnsplashSource.bindAttributes({
token: "token",
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as LR from "@uploadcare/blocks";
import { CustomFileUploader } from "./CustomFileUploader.js";
import { CustomSourceBtn } from "./CustomSourceBtn.js";
import { UnsplashSource } from "./UnsplashSource.js";
import cssSrc from './style.css?url';
import './style.css';

LR.registerBlocks({
...LR,
Expand All @@ -11,14 +11,6 @@ LR.registerBlocks({
SourceBtn: CustomSourceBtn,
});

const uploader = document.querySelector("lr-custom-file-uploader");
uploader.setAttribute('css-src', cssSrc);
if (!import.meta.env.VITE_UNSPLASH_TOKEN) {
throw new Error("VITE_UNSPLASH_TOKEN is not defined");
}

// TODO: move to lr-config also
uploader.style.setProperty(
"--cfg-unsplash-token",
`"${import.meta.env.VITE_UNSPLASH_TOKEN}"`
);
}
Loading
Loading