Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add preview for scrollbar generator #567

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 24 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,30 @@ <h1>Input Range</h1>

<!-- Custom Scroll Generator -->
<div data-content="scroll">
<!-- custom scroll generator -->
<h2>Preview</h2>
<br />
<div id="scroll-preview">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
<br />
<div class="input">
<label for="color" class="color">
Track Color
Expand Down
3 changes: 3 additions & 0 deletions src/lib/getElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,6 @@ export const getGridFields = (

export const getGridPreview = (attribute: string): HTMLElement =>
document.getElementById(`${attribute}-preview`) as HTMLElement;

export const getScrollPreview = (): HTMLElement =>
document.getElementById('scroll-preview') as HTMLElement;
56 changes: 56 additions & 0 deletions src/pages/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getCopyCodeButton,
getCssOrTailwindButton,
getCssOrTailwindDropdown,
getScrollPreview,
} from '../lib/getElements';
import {closeDropdown, showPopup} from '../lib/packages/utils';

Expand Down Expand Up @@ -83,6 +84,61 @@ function copyHandler(values: Values) {
}

export function scrollGenerator() {
const previewElement = getScrollPreview();

function applyPreviewStyles(values: Values) {
if (!previewElement) return;

// Apply styles directly to the preview element
previewElement.style.setProperty('--scrollbar-width', `${values.width}px`);
previewElement.style.setProperty(
'--scrollbar-track-color',
values.trackColor
);
previewElement.style.setProperty(
'--scrollbar-thumb-color',
values.thumbColor
);
previewElement.style.setProperty(
'--scrollbar-thumb-hover-color',
values.hoverColor
);

const styleTag = document.createElement('style');
styleTag.id = 'scroll-preview-style';
styleTag.innerHTML = `
#scroll-preview::-webkit-scrollbar {
width: var(--scrollbar-width);
}
#scroll-preview::-webkit-scrollbar-track {
box-shadow: inset 0 0 5px var(--scrollbar-track-color);
}
#scroll-preview::-webkit-scrollbar-thumb {
background: var(--scrollbar-thumb-color);
}
#scroll-preview::-webkit-scrollbar-thumb:hover {
background: var(--scrollbar-thumb-hover-color);
}
`;

document.head.appendChild(styleTag);
}

function updatePreview() {
applyPreviewStyles({
trackColor: trackColor.value,
thumbColor: thumbColor.value,
hoverColor: hoverColor.value,
width: width.value,
});
}

[trackColor, thumbColor, hoverColor, width].forEach((input) => {
input?.addEventListener('input', updatePreview);
});

updatePreview();

getCodeButton?.addEventListener('click', () =>
copyHandler({
trackColor: trackColor.value,
Expand Down
8 changes: 8 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,14 @@ input[type='range']:focus::-moz-range-thumb {
color: var(--text-color);
}

#scroll-preview {
width: 300px;
height: 200px;
overflow-y: scroll;
border: 1px solid var(--text-color);
padding: 12px;
}

/* FOOTER SECTION */

footer {
Expand Down
Loading