Skip to content

Commit

Permalink
add button ui element
Browse files Browse the repository at this point in the history
  • Loading branch information
milewskibogumil committed Oct 15, 2024
1 parent 918294f commit 6b38ab8
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 65 deletions.
4 changes: 3 additions & 1 deletion apps/astro/astro.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { defineConfig } from "astro/config";
import vercel from "@astrojs/vercel/serverless";
import preact from '@astrojs/preact';
import sitemap from "@astrojs/sitemap";
import vercel from "@astrojs/vercel/serverless";
import { DOMAIN } from "./src/global/constants";
import { isPreviewDeployment } from "./src/utils/is-preview-deployment";
import redirects from "./redirects";

export default defineConfig({
site: DOMAIN,
integrations: [
preact({ compat: true }),
sitemap(),
],
image: {
Expand Down
5 changes: 5 additions & 0 deletions apps/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"dependencies": {
"@astrojs/check": "^0.9.4",
"@astrojs/preact": "^3.5.3",
"@astrojs/sitemap": "^3.2.0",
"@astrojs/vercel": "^7.8.1",
"@sanity/client": "^6.22.1",
Expand All @@ -28,5 +29,9 @@
"eslint-plugin-astro": "^1.2.4",
"eslint-plugin-jsx-a11y": "^6.10.0",
"sass": "^1.79.5"
},
"overrides": {
"react": "bun:@preact/compat@latest",
"react-dom": "bun:@preact/compat@latest"
}
}
118 changes: 118 additions & 0 deletions apps/astro/src/components/ui/button/button.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
.button {
font-size: var(--typography-body-m, 14px);
position: relative;
overflow: hidden;
z-index: 2;
border-radius: 4px;
display: inline-flex;
justify-content: center;
align-items: center;
min-height: 3rem;
padding: 0 clamp(1rem, calc(1rem + 1vw / 0.48), 2rem);
transition: transform 500ms var(--easing);
@media (max-width: 499px) {
width: 100%;
}
&::before {
content: '';
width: 110%;
aspect-ratio: 1/1;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
z-index: -1;
background-image: conic-gradient(
var(--primary-500, #064040) 79%,
#90f4e8 87%,
#90f4e8 92%,
var(--primary-500, #064040) 100%
);
animation: rotate 2.5s linear infinite;
animation-play-state: paused;
transition: opacity 500ms var(--easing);
@keyframes rotate {
from {
transform: translate(-50%, -50%) rotate(0deg);
}
to {
transform: translate(-50%, -50%) rotate(360deg);
}
}
}
&::after {
content: '';
position: absolute;
z-index: -1;
left: 1px;
top: 1px;
right: 1px;
bottom: 1px;
border-radius: inherit;
background: linear-gradient(266deg, #0b0f0d, #011310, #001f1b);
}
.content {
display: inline-flex;
align-items: center;
gap: 0.5rem;
z-index: 2;
border-radius: inherit;
}
&[data-theme='primary'] {
span {
background: linear-gradient(266deg, #2dd282, #90f4e8);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.content {
&::before {
content: '';
position: absolute;
z-index: -1;
left: 0;
top: 0;
right: 0;
bottom: 0;
background:
linear-gradient(var(--neutral-900, #000103), var(--neutral-900, #000103)) padding-box,
linear-gradient(266deg, #2dd282, #90f4e8) border-box;
border: 1px solid rgba(255, 255, 255, 0);
border-radius: inherit;
transition: opacity 500ms var(--easing);
}
}
}
&[data-theme='secondary'] {
border-radius: 48px;
&::before {
opacity: 0;
}
}
&:disabled {
opacity: 0.62;
pointer-events: none;
}
img {
width: 28px;
height: 28px;
}
&:hover {
&::before {
animation-play-state: running;
@media (prefers-reduced-motion) {
animation-play-state: paused;
}
opacity: 1;
}
.content {
&::before {
opacity: 0;
}
}
}
&:active {
transition: none;
transform: scale(0.99);
}
}
32 changes: 32 additions & 0 deletions apps/astro/src/components/ui/button/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { ImageDataProps } from '../image';
import styles from './button.module.scss'

export type Props = React.HTMLAttributes<HTMLAnchorElement> & React.ButtonHTMLAttributes<HTMLButtonElement> & {
text?: string | React.ReactNode
children: React.ReactNode;
theme?: 'primary' | 'secondary'
linkType?: 'external' | 'internal'
href?: string
img?: ImageDataProps
className?: string
}

export default function Button({ children, text, theme = 'primary', linkType = 'internal', href, img, className, ...props }: Props) {
const Element = href ? 'a' : 'button'
const isExternal = linkType === 'external'
const renderedProps = {
...(href && { href }),
...(isExternal && { target: '_blank', rel: 'noreferrer' }),
'data-theme': theme,
className: `${styles.button}${className ? ` ${className}` : ''}`,
...props,
}

return (
<Element {...renderedProps}>
<div className={styles.content}>
{children}
</div>
</Element>
)
}
36 changes: 36 additions & 0 deletions apps/astro/src/components/ui/button/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
import Image from '@/components/ui/image'
import Button, { type Props as ButtonDataProps } from './button'
type Props = ButtonDataProps
const { ...props } = Astro.props
const svgId = `arrow-icon-${Math.random().toString(36).slice(2, 9)}`
---

<Button {...props}>
<span>
{props.text || <slot />}
</span>
{
props.img ? (
<Image {...props.img} sizes="28px" class="gradient-thumbnail" />
) : (
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="17" fill="none">
<path
stroke={`url(#${svgId})`}
stroke-linecap="round"
stroke-linejoin="round"
d="M2.664 8.5h10.667m0 0-4-4m4 4-4 4"
/>
<defs>
<linearGradient id={svgId} x1="13.131" x2="2.064" y1="4.5" y2="5.44" gradientUnits="userSpaceOnUse">
<stop stop-color="#2DD282" />
<stop offset="1" stop-color="#90F4E8" />
</linearGradient>
</defs>
</svg>
)
}
</Button>
13 changes: 13 additions & 0 deletions apps/astro/src/components/ui/button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ImageDataQuery } from '../image';
export { default } from './index.astro';
export { type Props as ButtonDataProps } from './button';

export const ButtonDataQuery = (name: string) => `
${name} {
text,
theme,
linkType,
"href": select(linkType == "internal" => internal -> slug.current, linkType == "external" => external, "#"),
${ImageDataQuery('img')}
},
`
33 changes: 22 additions & 11 deletions apps/astro/src/global/global.scss
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
@font-face {
font-family: 'Poppins';
font-family: 'KryptoPoppins';
src:
url('/fonts/Poppins-Regular.woff2') format('woff2'),
url('/fonts/Poppins-Regular.woff') format('woff');
url('/fonts/KryptoPoppins-Regular.woff2') format('woff2'),
url('/fonts/KryptoPoppins-Regular.woff') format('woff');
font-weight: 400;
font-display: swap;
font-style: normal;
}
@font-face {
font-family: 'Poppins Fallback';
font-family: 'KryptoPoppins Fallback';
src: local('Arial');
size-adjust: 109%;
ascent-override: 100%;
descent-override: 27%;
line-gap-override: 5%;
ascent-override: 93.76%;
descent-override: 31.25%;
line-gap-override: 8.93%;
size-adjust: 111.99%;
}

*,
Expand Down Expand Up @@ -144,7 +144,7 @@
--menu-text: var(--neutral-200);
--background: var(--neutral-900);

--easing: cubic-bezier(0.215, 0.61, 0.355, 1);
--easing: cubic-bezier(0.19, 1, 0.22, 1);

// Margins
--page-margin: clamp(1rem, calc(2vw / 0.48), 2rem);
Expand Down Expand Up @@ -230,7 +230,7 @@ img {
}
:focus-visible {
outline: 2px solid var(--neutral-200, #f0f7f7);
outline-offset: 3px;
outline-offset: 5px;
}

html,
Expand All @@ -239,6 +239,9 @@ body {
}
html {
scroll-behavior: smooth;
@media (prefers-reduced-motion) {
scroll-behavior: none;
}
scroll-padding-top: 123px;
&::-webkit-scrollbar {
width: 16px;
Expand All @@ -257,7 +260,7 @@ body {
-webkit-tap-highlight-color: transparent;
background-color: var(--neutral-900, #000103);
color: var(--neutral-200, #f0f7f7);
font-family: 'Poppins', 'Poppins Fallback', sans-serif;
font-family: 'KryptoPoppins', 'KryptoPoppins Fallback', sans-serif;
font-size: var(--typography-body-xl, 1rem);
line-height: 175%;
letter-spacing: 0.005em;
Expand Down Expand Up @@ -380,3 +383,11 @@ li {
align-items: center;
gap: clamp(1rem, calc(1.5vw / 0.48), 2rem);
}

.gradient-thumbnail {
background:
linear-gradient(var(--neutral-900), var(--neutral-900)) padding-box,
linear-gradient(266deg, #2dd282, #90f4e8) border-box;
border: 1px solid rgba(255, 255, 255, 0);
border-radius: 50%;
}
Loading

0 comments on commit 6b38ab8

Please sign in to comment.