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

Add click to copy behavior #119

Merged
merged 34 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
188906b
Add click to copy behavior
jamesnw Aug 15, 2023
affb40c
add clipboard icon and styles for copy
stacyk Aug 21, 2023
c55d070
Add copy component, switch icon after copy
jamesnw Aug 22, 2023
ff3d931
Lint
jamesnw Aug 22, 2023
e0ae972
copied icon
stacyk Sep 25, 2023
e391e31
Merge branch '100-copy-colors-to-clipboard' of https://github.com/odd…
stacyk Sep 25, 2023
195a0c3
add new copy(copied) button
stacyk Sep 25, 2023
6752d13
adjust grid track size for icons
stacyk Sep 25, 2023
ec4f273
add icon documentation and color option for success icon
stacyk Sep 25, 2023
b23230b
add animation documentation
stacyk Sep 25, 2023
22db19f
update test
stacyk Sep 26, 2023
b6f7af2
update easing variable name
stacyk Sep 26, 2023
1432d95
Merge branch 'main' into 100-copy-colors-to-clipboard
jgerigmeyer Sep 26, 2023
916eac5
Allow importing from node_modules in Herman examples.
jgerigmeyer Sep 26, 2023
cde9f03
change css to sass comments
stacyk Sep 26, 2023
609b5ff
remove less helpful keyframe animation documentation
stacyk Sep 26, 2023
e5fea47
remove heading from sassdoc comments
stacyk Sep 26, 2023
63738d3
adjust type and breakpoints to accomodate new clipboard icon
stacyk Sep 26, 2023
74e172e
add fixed ratio width to prevent jumping in results
stacyk Sep 26, 2023
b3da1cb
lint
stacyk Sep 26, 2023
e54b914
review
jgerigmeyer Sep 26, 2023
27b6376
clean up alpha order
stacyk Sep 27, 2023
98dd933
add transform to button transition
stacyk Sep 27, 2023
7fa832c
move input styles to global pattern
stacyk Sep 27, 2023
7624868
remove unused
stacyk Sep 27, 2023
caa6a9d
update range thumb focus color
stacyk Sep 27, 2023
b62fd12
switch to using focus-visible
stacyk Sep 27, 2023
be37579
add link transform, move social nav to component
stacyk Sep 27, 2023
dc9cf67
add icon-only button focus styles
stacyk Sep 27, 2023
776a54b
update focus mixin
stacyk Sep 27, 2023
4a16883
align warning text with input
stacyk Sep 27, 2023
be56d59
Merge branch '100-copy-colors-to-clipboard' of https://github.com/odd…
stacyk Sep 27, 2023
91575ef
lint
stacyk Sep 27, 2023
392d049
lighten icon actions
stacyk Sep 29, 2023
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
1 change: 1 addition & 0 deletions .sassdocrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ herman:
sassOptions:
loadPaths:
- 'src/sass'
- 'node_modules'
use:
- 'config'
display:
Expand Down
8 changes: 0 additions & 8 deletions src/lib/components/Footer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,3 @@
{/each}
</ul>
</footer>

<style lang="scss">
[data-nav='social'] {
--li-padding-bottom: 0;
--link: var(--text);
--link-focus: var(--action);
}
</style>
17 changes: 9 additions & 8 deletions src/lib/components/colors/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import type { PlainColorObject } from 'colorjs.io/types/src/color';
import type { Writable } from 'svelte/store';

import CopyButton from '$lib/components/util/CopyButton.svelte';
import type { ColorFormatId } from '$lib/constants';
import { getSpaceFromFormatId } from '$lib/utils';

Expand All @@ -13,8 +14,8 @@
$: targetSpace = getSpaceFromFormatId(format);
$: display = serialize($color, { inGamut: false, format });
$: displayType = type === 'bg' ? 'Background' : 'Foreground';
$: editing = false;
$: inputValue = '';
let editing = false;
let inputValue = '';
let hasError = false;

// When not editing, sync input value with color (e.g. when sliders change)
Expand Down Expand Up @@ -86,6 +87,7 @@
on:input={handleInput}
on:keydown={handleKeydown}
/>
<CopyButton text={display} size="medium" />
{#if hasError}
<div data-color-info="warning">Could not parse input as a valid color.</div>
{/if}
Expand All @@ -95,12 +97,13 @@
@use 'config';

[data-colors] {
align-items: center;
display: grid;
grid-template:
'label' auto
'swatch' var(--swatch-height, var(--swatch))
'input' auto
'error' minmax(var(--double-gutter), auto) / 1fr;
'label label' auto
'swatch swatch' var(--swatch-height, var(--swatch))
'copy input' auto
'.... error' minmax(var(--double-gutter), auto) / auto 1fr;

@include config.above('sm-page-break') {
--swatch-height: calc(2 * var(--swatch));
Expand Down Expand Up @@ -154,9 +157,7 @@
}

[data-input='color'] {
border-width: 0 0 var(--border-width) 0;
grid-area: input;
padding: var(--shim) 0.25ch;
}

[data-color-info='warning'] {
Expand Down
19 changes: 19 additions & 0 deletions src/lib/components/colors/Output.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import type { PlainColorObject } from 'colorjs.io/types/src/color';

import SupportWarning from '$lib/components/colors/SupportWarning.svelte';
import CopyButton from '$lib/components/util/CopyButton.svelte';
import type { ColorFormatId } from '$lib/constants';
import { getSpaceFromFormatId } from '$lib/utils';

Expand All @@ -21,6 +22,7 @@

<ul data-group="output {type}">
<li>
<CopyButton text={targetColorValue} />
<span data-color-info="value">{targetColorValue}</span>
<SupportWarning {format} />
{#if !isInGamut}
Expand All @@ -30,3 +32,20 @@
{/if}
</li>
</ul>

<style lang="scss">
li {
display: grid;
grid-template:
'copy color' auto
'copy message' 3ex / auto 1fr;
}

[data-color-info='value'] {
grid-area: color;
}

[data-color-info='warning'] {
grid-area: message;
}
</style>
4 changes: 3 additions & 1 deletion src/lib/components/ratio/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@

@include config.between('sm-column-break', 'lg-page-break') {
gap: var(--shim) var(--gutter);
// fixed width column to prevent layout shift as the ratio number changes
grid-template:
'heading number' min-content
'intro intro' 1fr / auto 1fr;
'intro intro' 1fr / auto var(--ratio-width);
mirisuzanne marked this conversation as resolved.
Show resolved Hide resolved
mirisuzanne marked this conversation as resolved.
Show resolved Hide resolved
}

@include config.above('lg-page-break') {
Expand Down Expand Up @@ -134,6 +135,7 @@
align-items: start;
display: inline-flex;
grid-area: number;
justify-content: flex-end;
line-height: 0.7; // weird number alignment
}

Expand Down
28 changes: 28 additions & 0 deletions src/lib/components/util/CopyButton.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script lang="ts">
import Icon from '$lib/components/util/Icon.svelte';

export let text: string;
export let size: string | null = null;

let justCopied = false;
let timeout: ReturnType<typeof setTimeout>;

const copyOutput = () => {
justCopied = true;
void navigator.clipboard.writeText(text);
clearTimeout(timeout);
timeout = setTimeout(() => {
justCopied = false;
}, 1000);
};
</script>

<button on:click={copyOutput} type="button" data-btn="icon">
{#if !justCopied}
<Icon name="clipboard" {size} />
<span class="sr-only">Click to copy</span>
{:else}
<Icon name="copy" {size} />
<span class="sr-only">Copied</span>
{/if}
</button>
4 changes: 4 additions & 0 deletions src/lib/components/util/Icon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import type { SvelteComponent } from 'svelte';

import Check from '$lib/icons/Check.svelte';
import Clipboard from '$lib/icons/Clipboard.svelte';
import Copy from '$lib/icons/Copy.svelte';
import GitHub from '$lib/icons/GitHub.svelte';
import LinkedIn from '$lib/icons/LinkedIn.svelte';
import Logo from '$lib/icons/Logo.svelte';
Expand All @@ -14,6 +16,8 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const icons: { [key: string]: typeof SvelteComponent<any> } = {
check: Check,
clipboard: Clipboard,
copy: Copy,
logo: Logo,
newtab: NewTab,
warning: Warning,
Expand Down
14 changes: 14 additions & 0 deletions src/lib/icons/Clipboard.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24.12 24.12"
{...$$restProps}
>
<path
id="arrow"
d="m14.37,12.26l-.55.06v-1.65c0-.27-.18-.4-.25-.44-.08-.04-.28-.13-.51,0l-5.56,3.21c-.23.13-.25.35-.25.44s.02.31.25.44l5.56,3.21c.23.13.43.04.51,0s.25-.18.25-.44v-1.26l.44-.06c.91-.12,1.76-.17,2.54-.17,3.74,0,6.02,1.2,7.32,2.28-2.06-5.77-7.38-5.89-9.74-5.63h0Z"
/>
<path
id="clipboard"
d="m19.22,21.9c0,.33-.27.6-.6.6H2.25c-.33,0-.6-.27-.6-.6V5.3c0-.33.27-.6.6-.6h.6v.6c0,.8.65,1.45,1.45,1.45h12.28c.8,0,1.45-.65,1.45-1.45v-.6h.6c.33,0,.6.27.6.6v6.47c.55.18,1.09.41,1.63.7v-6.96c0-1.34-1.09-2.43-2.42-2.43h-2.29c-.25-.56-.81-.95-1.46-.95h-2.13c-.29,0-.53-.24-.53-.53,0-.88-.71-1.6-1.6-1.6s-1.6.71-1.6,1.6c0,.29-.24.53-.53.53h-2.13c-.65,0-1.21.39-1.46.95h-2.29c-1.34,0-2.42,1.09-2.42,2.43v16.18c0,1.34,1.09,2.43,2.42,2.43h16c1.34,0,2.42-1.09,2.42-2.43v-4.42c-.49-.17-1.03-.31-1.63-.41v5.05h0Z"
/>
</svg>
15 changes: 15 additions & 0 deletions src/lib/icons/Copy.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24.12 24.12"
data-icon-theme="success"
{...$$restProps}
>
<path
id="checkmark"
d="m4.59,13.25c1.26.68,4.17,2.37,5.48,4.21.09.13.28.12.35-.02.87-1.66,4.8-10.28,12.46-8.69,0,0-7.71-4.73-13.37,4.62,0,0-1.09-.83-2.01-2.18-.14-.2-.41-.27-.62-.14l-2.32,1.49c-.26.17-.25.54.02.69v.02Z"
/>
<path
id="circle"
d="m19.14,10.58c.84,3.69-.78,7.66-4.23,9.63-4.23,2.42-9.64.95-12.07-3.29-1.61-2.81-1.49-6.14,0-8.77.76-1.33,1.86-2.48,3.28-3.3s2.97-1.18,4.5-1.15c2.04.03,4.02.76,5.6,2.09.1.09.21.17.31.26.58-.09,1.59-.1,2.18-.11-1.09-1.36-2.47-2.38-4-3.05-.71-.31-1.45-.54-2.21-.69-2.39-.46-4.95-.11-7.22,1.19S1.32,6.86.53,9.25C.22,10.19.04,11.17,0,12.17c-.07,1.9.36,3.83,1.37,5.6s2.46,3.12,4.13,4.02c2.04,1.1,4.41,1.51,6.73,1.13,1.2-.2,2.39-.6,3.51-1.24s2.07-1.46,2.85-2.4c1.33-1.6,2.15-3.54,2.38-5.57.14-1.24.06-2.5-.25-3.74-.49.09-1.14.22-1.64.4.02.07.04.14.06.21Z"
/>
</svg>
1 change: 1 addition & 0 deletions src/sass/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
@use 'config';
@use 'initial';
@use 'patterns';
@use 'components';
4 changes: 4 additions & 0 deletions src/sass/components/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Components Manifest
// ===================

@forward 'social-nav';
18 changes: 18 additions & 0 deletions src/sass/components/_social-nav.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[data-nav='social'] {
--li-padding-bottom: 0;
--link: var(--text);
--link-focus: var(--action);

a {
&:link,
&:visited {
--outline-width: 0;

display: block;

&:focus-visible {
transform: scale(1.15);
}
}
}
}
9 changes: 0 additions & 9 deletions src/sass/config/_animation.scss

This file was deleted.

6 changes: 3 additions & 3 deletions src/sass/config/_focus.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
/// @group focus
@mixin focus-ring() {
/* stylelint-disable declaration-block-no-redundant-longhand-properties */
outline-color: var(--focus-ring, var(--text, currentColor));
outline-color: var(--focus-ring, currentColor);
outline-offset: var(--outline-offset, 0);
outline-style: var(--outline-style, dotted);
outline-width: var(--outline-width, var(--border-width));
outline-style: var(--outline-style, solid);
outline-width: var(--outline-width, var(--border-width-md));
/* stylelint-enable declaration-block-no-redundant-longhand-properties */
}
16 changes: 10 additions & 6 deletions src/sass/config/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
@forward 'scale';
@forward 'utilities';

/**
* To turn Sass tokens into CSS custom properties:
* - load each color module with `@use`
* - use the `tools.add-colors` mixin with the `sass:meta` module to create a map of the variables in the imported module
* - in `initial/_root.scss` call the `config.colors--()` mixin to create custom properties
*/
// To turn Sass tokens into CSS custom properties:
// - load each color module with `@use`
// - use the `tools.add-*` mixin with the `sass:meta` module to create a
// map of the variables in the imported module
// - in `initial/_root.scss` call the `config.*--()` mixin to create
// custom properties
@use 'tools';
@use 'sass:meta';
@use 'animation/easing';
@use 'animation/times';
@use 'color/brand';
@use 'color/ui' as color-ui;
@use 'scale/ratio';
Expand All @@ -28,3 +30,5 @@
@include tools.add-sizes(meta.module-variables('spacing'));
@include tools.add-sizes(meta.module-variables('text'));
@include tools.add-sizes(meta.module-variables('scale-ui'));
@include tools.add-easing(meta.module-variables('easing'));
@include tools.add-times(meta.module-variables('times'));
5 changes: 3 additions & 2 deletions src/sass/config/_tools.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@forward 'accoutrement/sass/tools' with (
$size-var-prefix: '',
$ratio-var-prefix: '',
$color-var-prefix: '',
$easing-var-prefix: '',
$ratio-var-prefix: '',
$size-var-prefix: '',
$time-var-prefix: ''
);
1 change: 1 addition & 0 deletions src/sass/config/animation/_easing.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$springy: cubic-bezier(0.175, 0.885, 0.32, 1.275);
39 changes: 39 additions & 0 deletions src/sass/config/animation/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@use 'sassdoc-theme-herman/scss/utilities' as herman;
@use '../tools';
@use 'easing';
@use 'times';
@use 'sass:meta';
@forward 'easing';
@forward 'times';

/// # Animation Config
/// Accoutrement maps for storing global animation tokens.
/// @link https://www.oddbird.net/accoutrement/docs/animate.html
/// Accoutrement Animate
/// @group animation

/// ## Easing
/// ---------
/// Named easings that can be re-used to create consistent movement.
/// @group animation
/// @example scss
/// @use 'config/animation/easing';
/// @use 'config/tools';
/// @use 'sass:meta';
///
/// @each $name, $easing in tools.compile-easing(meta.module-variables('easing')) {
/// /* #{$name}: #{$easing}; */
/// }

/// ## Times
/// ---------
/// Named times that can be re-used to create consistent motion timing.
/// @group animation
/// @example scss
/// @use 'config/animation/times';
/// @use 'config/tools';
/// @use 'sass:meta';
///
/// @each $name, $time in tools.compile-times(meta.module-variables('times')) {
/// /* #{$name}: #{$time}; */
/// }
jgerigmeyer marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions src/sass/config/animation/_times.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$fast: 300ms;
$slow: 1000ms;
1 change: 1 addition & 0 deletions src/sass/config/color/_ui.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ $border-light: tools.tint(brand.$brand-blue, 65%);
$warning: tools.shade(brand.$brand-pink, 5%);
$action: tools.shade(brand.$brand-pink, 15%);
$active: brand.$brand-blue;
$success: oklab(51.527% -0.099 0.0131);
2 changes: 1 addition & 1 deletion src/sass/config/scale/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

$page: 60rem;
$sm-column-break: 30em;
$sm-page-break: 40em;
$sm-page-break: 42em;
Copy link
Member

Choose a reason for hiding this comment

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

had to move this up since we added the icon for longer formats like p3 to fit

$lg-page-break: 80em;
$page-margin: calc(spacing.$quarter-shim + 4vw);
2 changes: 2 additions & 0 deletions src/sass/config/scale/_ui.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ $logo: 12rem;
$swatch: 3.25rem;
$icon-size-default: 1.125em;
$icon-small: 0.65em;
$icon-medium: 1.65em;
$ratio-width: 10rem;
$range-thumb-size: 1.35rem;
$range-input: 0.85rem;
Loading