Skip to content

Commit

Permalink
Merge pull request #57 from code4rena-dev/develop
Browse files Browse the repository at this point in the history
Major Version - Image Upload Component
  • Loading branch information
leo95oliveira committed Mar 26, 2024
2 parents b825666 + dc92d8d commit 635cd70
Show file tree
Hide file tree
Showing 17 changed files with 689 additions and 11 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
name: Jest
on:
workflow_dispatch:
push:
branches: [ develop ]
pull_request:
branches: [ develop, main ]
jobs:
Expand Down
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ vercel.jsontsconfig.json
jest.config.ts
.storybook
.github
*DS_Store
*DS_Store
*.stories.tsx
*.test.tsx
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@code4rena/components-library",
"version": "3.2.1",
"version": "4.0.0",
"description": "Code4rena's official components library ",
"types": "./dist/lib.d.ts",
"exports": {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/ContestTile/CompactTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ const IsContest = ({title, isDarkTile = true, contestData, sponsorUrl, sponsorIm
{languages
&& languages.length > 0
&& languages.map((language) => <Tag
key={language}
variant={isDarkTile ? TagVariant.DEFAULT : TagVariant.WHITE_OUTLINE}
label={language}
size={TagSize.NARROW}
Expand Down Expand Up @@ -259,6 +260,7 @@ const IsBounty = ({title, isDarkTile = true, bountyData, sponsorUrl, sponsorImag
{languages
&& languages.length > 0
&& languages.map((language) => <Tag
key={language}
variant={isDarkTile ? TagVariant.DEFAULT : TagVariant.WHITE_OUTLINE}
label={language}
size={TagSize.NARROW} />
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ContestTile/ContestTile.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export enum ContestTileVariant {

export type ContestEcosystem = "Algorand" | "Aptos" | "Blast" | "Cosmos" | "EVM" | "NEAR" | "Polkadot" | "Scroll" | "Sei" | "Solana" | "StarkNet" | "Stellar" | "Sui" | "Other";

export type CodingLanguage = "Cairo" | "GO" | "HUFF" | "Ink" | "Move" | "Noir" | "Other" | "Rain" | "Rust" | "Rust evm" | "Solidity" | "Vyper" | "Yui";
export type CodingLanguage = "Cairo" | "GO" | "HUFF" | "Ink" | "Move" | "Noir" | "Other" | "Rain" | "Rust" | "Rust evm" | "Solidity" | "Vyper" | "Yul";

export interface ContestTileProps {
/** An html `id` for the contest tile's wrapping div. */
Expand Down
2 changes: 2 additions & 0 deletions src/lib/ContestTile/DefaultTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ function IsContest({
{languages
&& languages.length > 0
&& languages.map((language) => <Tag
key={language}
variant={isDarkTile ? TagVariant.DEFAULT : TagVariant.WHITE_OUTLINE}
label={language}
size={TagSize.NARROW} />
Expand Down Expand Up @@ -475,6 +476,7 @@ function IsBounty({
{languages
&& languages.length > 0
&& languages.map((language) => <Tag
key={language}
variant={isDarkTile ? TagVariant.DEFAULT : TagVariant.WHITE_OUTLINE}
label={language}
size={TagSize.NARROW} />
Expand Down
8 changes: 4 additions & 4 deletions src/lib/Icon/iconList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const icons = (size: string, color: string, className?: string): Record<s
<path fill={color} fillRule="evenodd" clipRule="evenodd" d="M10.6803 4.2636C11.0317 3.91213 11.6016 3.91213 11.953 4.2636L18.3697 10.6803C18.5385 10.8491 18.6333 11.078 18.6333 11.3167C18.6333 11.5554 18.5385 11.7843 18.3697 11.9531L11.953 18.3697C11.6016 18.7212 11.0317 18.7212 10.6803 18.3697C10.3288 18.0183 10.3288 17.4484 10.6803 17.0969L15.5605 12.2167H4.89998C4.40293 12.2167 3.99998 11.8137 3.99998 11.3167C3.99998 10.8196 4.40293 10.4167 4.89998 10.4167H15.5605L10.6803 5.5364C10.3288 5.18492 10.3288 4.61508 10.6803 4.2636Z" />
</g>
</svg>,
"bell": <svg width={size} height={size} viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
"bell": <svg className={className} width={size} height={size} viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path stroke={color} d="M15.1333 8.33333C15.1333 7.18406 14.6768 6.08186 13.8641 5.2692C13.0515 4.45655 11.9493 4 10.8 4C9.65072 4 8.54852 4.45655 7.73586 5.2692C6.9232 6.08186 6.46665 7.18406 6.46665 8.33333C6.46665 13.3889 4.29999 14.8333 4.29999 14.8333H17.3C17.3 14.8333 15.1333 13.3889 15.1333 8.33333Z" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
<path stroke={color} d="M12.0495 17.7223C11.9225 17.9412 11.7402 18.1229 11.521 18.2492C11.3017 18.3755 11.0531 18.442 10.8 18.442C10.547 18.442 10.2983 18.3755 10.0791 18.2492C9.85979 18.1229 9.67754 17.9412 9.55057 17.7223" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
</svg>,
Expand Down Expand Up @@ -110,13 +110,13 @@ export const icons = (size: string, color: string, className?: string): Record<s
</g>
</g>
</svg>,
"eye-closed": <svg width={size} height={size} viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
"eye-closed": <svg className={className} width={size} height={size} viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill={color} fillRule="evenodd" clipRule="evenodd" d="M15.0171 11.662C15.4634 11.3367 16.0889 11.4348 16.4142 11.8812L18.6831 14.9943C19.0084 15.4407 18.9103 16.0662 18.464 16.3915C18.0177 16.7168 17.3921 16.6186 17.0669 16.1723L14.7979 13.0591C14.4726 12.6128 14.5708 11.9873 15.0171 11.662Z" />
<path fill={color} fillRule="evenodd" clipRule="evenodd" d="M11 12.75C11.5523 12.75 12 13.1977 12 13.75V16.9583C12 17.5106 11.5523 17.9583 11 17.9583C10.4477 17.9583 10 17.5106 10 16.9583V13.75C10 13.1977 10.4477 12.75 11 12.75Z" />
<path fill={color} fillRule="evenodd" clipRule="evenodd" d="M6.9772 11.6699C7.42352 11.9952 7.52164 12.6207 7.19635 13.067L4.93314 16.1723C4.60785 16.6186 3.98234 16.7168 3.53601 16.3915C3.08969 16.0662 2.99157 15.4407 3.31686 14.9943L5.58007 11.889C5.90536 11.4427 6.53087 11.3446 6.9772 11.6699Z" />
<path fill={color} fillRule="evenodd" clipRule="evenodd" d="M2.33964 7.33808C2.84328 7.11144 3.43529 7.336 3.66192 7.83964C6.60814 14.3868 15.3919 14.3868 18.3381 7.83964C18.5647 7.336 19.1567 7.11144 19.6604 7.33808C20.164 7.56472 20.3886 8.15673 20.1619 8.66037C16.5081 16.7799 5.49186 16.7799 1.83808 8.66037C1.61144 8.15673 1.836 7.56472 2.33964 7.33808Z" />
</svg>,
"eye-open": <svg width={size} height={size} viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
"eye-open": <svg className={className} width={size} height={size} viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill={color} fillRule="evenodd" clipRule="evenodd" d="M18.3381 11.4104C15.3919 4.86321 6.60814 4.86321 3.66192 11.4104C3.43529 11.914 2.84328 12.1386 2.33964 11.9119C1.836 11.6853 1.61144 11.0933 1.83808 10.5896C5.49186 2.47012 16.5081 2.47012 20.1619 10.5896C20.3886 11.0933 20.164 11.6853 19.6604 11.9119C19.1567 12.1386 18.5647 11.914 18.3381 11.4104Z" />
<path fill={color} fillRule="evenodd" clipRule="evenodd" d="M3.66192 10.5896C6.60814 17.1368 15.3919 17.1368 18.3381 10.5896C18.5647 10.086 19.1567 9.86144 19.6604 10.0881C20.164 10.3147 20.3886 10.9067 20.1619 11.4104C16.5081 19.5299 5.49186 19.5299 1.83808 11.4104C1.61144 10.9067 1.836 10.3147 2.33964 10.0881C2.84328 9.86144 3.43528 10.086 3.66192 10.5896Z" />
<path fill={color} fillRule="evenodd" clipRule="evenodd" d="M11 9.25C10.0335 9.25 9.25 10.0335 9.25 11C9.25 11.9665 10.0335 12.75 11 12.75C11.9665 12.75 12.75 11.9665 12.75 11C12.75 10.0335 11.9665 9.25 11 9.25ZM7.25 11C7.25 8.92889 8.92889 7.25 11 7.25C13.0711 7.25 14.75 8.92889 14.75 11C14.75 13.0711 13.0711 14.75 11 14.75C8.92889 14.75 7.25 13.0711 7.25 11Z" />
Expand All @@ -134,7 +134,7 @@ export const icons = (size: string, color: string, className?: string): Record<s
</g>
</g>
</svg>,
"grab-vertical": <svg width={size} height={size} viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
"grab-vertical": <svg className={className} width={size} height={size} viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle fill={color} cx="13.75" cy="5.08325" r="1.75" />
<circle fill={color} cx="13.75" cy="11.0833" r="1.75" />
<circle fill={color} cx="13.75" cy="17.0833" r="1.75" />
Expand Down
168 changes: 168 additions & 0 deletions src/lib/ImageUpload/ImageUpload.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
@import "../../styles/variables";

.c4imgupload--wrapper {
display: flex;
flex-direction: column;
gap: 0.5rem;
max-width: 275px;
align-items: center;

.c4imgupload--preview {
width: 100%;

.preview {
position: relative;
height: 155px;
background: $color__n-90;

img {
width: 100%;
height: 100%;
object-fit: cover;
}

.cutout {
position: absolute;
display: flex;
flex-direction: row;
inset: 0;

.left, .right {
height: 100%;
width: calc((100% - 155px) / 2);
background: black;
opacity: 0.6;
}

.center{
border-radius: 0.25rem;
width: 155px;
height: 155px;
background: white;
opacity: 0.3;
}
}
}

.file-name {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
gap: 0.5rem;
padding: 0.5rem 1.5rem;
background: $color__n-90;
border: 1px solid $color__n-60;
border-top: 0;

p {
margin: 0;
font-size: $font-size__text;
line-height: 145%;
color: $color__n-20;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

button {
padding: 0;
background: transparent;
border: 0;
height: 24px;
width: 24px;
cursor: pointer;
}
}
}

.c4imgupload {
position: relative;
width: 100%;

&:hover {
.c4imgupload--container {
background: $color__n-80 !important;
border: 1px solid $color__n-50 !important;
}
}

.c4imgupload--container {
position: relative;
border: 1px solid $color__n-60;
background: $color__n-90;
height: auto;
border-radius: 0.25rem;
padding: 1rem;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;

&.active {
background: $color__n-80 !important;
border: 1px solid $color__n-50 !important;
}

input {
position: absolute;
inset: 0;
z-index: 1;
opacity: 0 !important;
color: transparent !important;
cursor: pointer;
}

svg {
width: 100%;
height: 100%;
min-width: 48px;
min-height: 48px;
max-width: 48px;
max-height: 48px;

path {
fill: $color__n-20;
}
}

.c4imgupload--caption {
line-height: 125%;
font-family: $font__default;
font-size: $font-size__text;
font-weight: bold;
text-align: center;
margin: 0;
color: $color__n-20;
max-width: 150px;

strong {
color: $color__blurple__text;
}
}
}

.c4imgupload--dragindicator {
visibility: hidden;
position: absolute;
inset: 0.35rem;
border-radius: 0.25rem;
border: 3px dashed $color__blurple__text;
z-index: 1;

&.active {
visibility: visible;
}
}
}

.c4imgupload--error {
color: $color__red;
margin: 0;
text-align: center;
width: 100%;
max-width: 420px;
font-size: 0.875rem;
line-height: normal;
}
}
30 changes: 30 additions & 0 deletions src/lib/ImageUpload/ImageUpload.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react";
import { Meta, StoryObj } from "@storybook/react";
import { ImageUpload } from "./ImageUpload"
import { ImageType } from "./ImageUpload.types";

const meta: Meta<typeof ImageUpload> = {
component: ImageUpload,
title: "Components/Image Upload",
tags: ["autodocs"]
};
export default meta;

type Story = StoryObj<typeof ImageUpload>;

export const SampleComponent: Story = (args) => (
<div style={{ minWidth: '300px', maxWidth: '420px' }}>
<ImageUpload {...args} />
</div>
)

SampleComponent.parameters = {
docs: {
canvas: {sourceState: "shown" }
}
};
SampleComponent.args = {
id: "c4_img_uploader",
accept: [ImageType.png, ImageType.jpeg],
maxSize: 2
}
Loading

0 comments on commit 635cd70

Please sign in to comment.