Compare commits
5 Commits
main
...
test-entit
Author | SHA1 | Date | |
---|---|---|---|
6e87595e2f | |||
d387e5c5bf | |||
1fd0f946e6 | |||
|
484f1f205e | ||
|
65b90f9636 |
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 26.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 13 13" style="enable-background:new 0 0 13 13;" xml:space="preserve">
|
||||
<path d="M9.5,6H7V3.5C7,3.22,6.78,3,6.5,3S6,3.22,6,3.5V6H3.5C3.22,6,3,6.22,3,6.5S3.22,7,3.5,7H6v2.5C6,9.78,6.22,10,6.5,10
|
||||
S7,9.78,7,9.5V7h2.5C9.78,7,10,6.78,10,6.5S9.78,6,9.5,6z"/>
|
||||
</svg>
|
Before Width: | Height: | Size: 541 B |
15
front/public/images/svg/upload.svg
Normal file
15
front/public/images/svg/upload.svg
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 26.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 15 13" style="enable-background:new 0 0 15 13;" xml:space="preserve">
|
||||
<g>
|
||||
<path d="M7.85,7.08C7.81,7.04,7.75,7,7.69,6.98c-0.12-0.05-0.26-0.05-0.38,0C7.25,7,7.19,7.04,7.15,7.08l-2.5,2.5
|
||||
c-0.2,0.2-0.2,0.51,0,0.71s0.51,0.2,0.71,0L7,8.64v3.79c0,0.28,0.22,0.5,0.5,0.5S8,12.71,8,12.44V8.64l1.65,1.65
|
||||
c0.1,0.1,0.23,0.15,0.35,0.15s0.26-0.05,0.35-0.15c0.2-0.2,0.2-0.51,0-0.71L7.85,7.08z"/>
|
||||
<path d="M9.38,0.06c-2.6,0-4.83,1.85-5.36,4.38H3.44c-1.83,0-3.31,1.49-3.31,3.31c0,1.01,0.45,1.95,1.23,2.58
|
||||
c0.27,0.22,0.57,0.39,0.89,0.51c0.06,0.02,0.12,0.03,0.18,0.03c0.2,0,0.39-0.12,0.47-0.32c0.1-0.26-0.03-0.55-0.29-0.65
|
||||
C2.38,9.82,2.17,9.7,1.99,9.55c-0.55-0.44-0.86-1.1-0.86-1.8c0-1.27,1.04-2.31,2.31-2.31h1c0.25,0,0.46-0.19,0.5-0.44
|
||||
c0.28-2.24,2.19-3.94,4.44-3.94c2.48,0,4.5,2.02,4.5,4.5c0,1.29-0.56,2.53-1.53,3.38c-0.21,0.18-0.23,0.5-0.05,0.71
|
||||
c0.18,0.21,0.5,0.23,0.71,0.05c1.19-1.04,1.87-2.55,1.87-4.13C14.88,2.53,12.41,0.06,9.38,0.06z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.2 KiB |
51
front/src/api/api.ts
Normal file
51
front/src/api/api.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import { BASE_URL } from './constants';
|
||||
import { ApiResponse } from './types';
|
||||
import { unpack } from './utils';
|
||||
|
||||
const send = async <T>(
|
||||
url: string,
|
||||
init: RequestInit,
|
||||
): Promise<ApiResponse<T>> => {
|
||||
const fullURL = `${BASE_URL}/${url}`;
|
||||
const fullInit: RequestInit = { ...init };
|
||||
try {
|
||||
const response = await fetch(fullURL, fullInit);
|
||||
if (!response.ok) {
|
||||
return {
|
||||
data: null,
|
||||
error: { status: response.status, message: 'Something went wrong' },
|
||||
};
|
||||
}
|
||||
const raw = await response.json();
|
||||
const data: T = unpack(raw);
|
||||
return { data: data, error: null };
|
||||
} catch {
|
||||
return {
|
||||
data: null,
|
||||
error: { status: 0, message: 'Something went wrong' },
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const api = {
|
||||
get: async <T>(url: string) => {
|
||||
return send<T>(url, { method: 'GET' });
|
||||
},
|
||||
post: async <T>(url: string, body: unknown) => {
|
||||
return send<T>(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
},
|
||||
put: async <T>(url: string, body: unknown) => {
|
||||
return send<T>(url, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
},
|
||||
delete: async <T>(url: string) => {
|
||||
return send<T>(url, { method: 'DELETE' });
|
||||
},
|
||||
};
|
1
front/src/api/constants.ts
Normal file
1
front/src/api/constants.ts
Normal file
@ -0,0 +1 @@
|
||||
export const BASE_URL = 'http://localhost:8000';
|
@ -1,2 +0,0 @@
|
||||
// export const BASE_URL = 'http://localhost:8000/api';
|
||||
export const BASE_URL = 'http://192.168.1.110:8000/api';
|
@ -1 +0,0 @@
|
||||
export { downloadImage, getWindmillData } from './service';
|
@ -1,26 +0,0 @@
|
||||
import { WindmillFormStore } from '@components/ux/windmill-form';
|
||||
|
||||
import { BASE_URL } from './constants';
|
||||
import { GetWindmillDataRes } from './types';
|
||||
import { getWindmillDataParams } from './utils';
|
||||
|
||||
export const getWindmillData = async (store: Partial<WindmillFormStore>) => {
|
||||
const params = getWindmillDataParams(store);
|
||||
const url = `${BASE_URL}/floris/get_windmill_data?${params}`;
|
||||
const init: RequestInit = {
|
||||
method: 'GET',
|
||||
};
|
||||
const res: Response = await fetch(url, init);
|
||||
const data: GetWindmillDataRes = await res.json();
|
||||
return data;
|
||||
};
|
||||
|
||||
export const downloadImage = async (imageName: string) => {
|
||||
const url = `${BASE_URL}/floris/download_image/${imageName}`;
|
||||
const init: RequestInit = {
|
||||
method: 'GET',
|
||||
};
|
||||
const res: Response = await fetch(url, init);
|
||||
const data = await res.blob();
|
||||
return data;
|
||||
};
|
@ -1,4 +0,0 @@
|
||||
export type GetWindmillDataRes = {
|
||||
file_name: string;
|
||||
data: number[];
|
||||
};
|
@ -1,9 +0,0 @@
|
||||
import { WindmillFormStore } from '@components/ux/windmill-form';
|
||||
|
||||
export const getWindmillDataParams = (store: Partial<WindmillFormStore>) => {
|
||||
const layoutX = store.windmills?.map((row) => `layout_x=${row.x}`).join('&');
|
||||
const layoutY = store.windmills?.map((row) => `layout_y=${row.y}`).join('&');
|
||||
const dateStart = `date_start=${store.dateFrom?.substring(0, 10)}`;
|
||||
const dateEnd = `date_end=${store.dateTo?.substring(0, 10)}`;
|
||||
return `${layoutX}&${layoutY}&${dateStart}&${dateEnd}`;
|
||||
};
|
@ -1 +0,0 @@
|
||||
export * from './floris';
|
9
front/src/api/types.ts
Normal file
9
front/src/api/types.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export type ApiError = {
|
||||
status: number;
|
||||
message: string;
|
||||
};
|
||||
|
||||
export type ApiResponse<T> = {
|
||||
data: T | null;
|
||||
error: ApiError | null;
|
||||
};
|
23
front/src/api/utils.ts
Normal file
23
front/src/api/utils.ts
Normal file
@ -0,0 +1,23 @@
|
||||
export const toCamelCase = (str: string) => {
|
||||
return str
|
||||
.split(/[_\s-]+|(?=[A-Z])/)
|
||||
.map((word, index) =>
|
||||
index === 0
|
||||
? word.toLowerCase()
|
||||
: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(),
|
||||
)
|
||||
.join('');
|
||||
};
|
||||
|
||||
export const unpack = (obj: unknown) => {
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map((item) => unpack(item));
|
||||
} else if (obj !== null && typeof obj === 'object') {
|
||||
return Object.entries(obj).reduce((acc, [key, value]) => {
|
||||
const newKey = toCamelCase(key);
|
||||
acc[newKey] = unpack(value);
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
return obj;
|
||||
};
|
6
front/src/api/wind/constants.ts
Normal file
6
front/src/api/wind/constants.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export const WIND_ENDPOINTS = {
|
||||
turbines: 'api/wind/turbines',
|
||||
turbineType: 'api/wind/turbine_type',
|
||||
parks: 'api/wind/parks',
|
||||
park: 'api/wind/park',
|
||||
};
|
2
front/src/api/wind/index.ts
Normal file
2
front/src/api/wind/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './service';
|
||||
export { type Park, type TurbineType } from './types';
|
48
front/src/api/wind/service.ts
Normal file
48
front/src/api/wind/service.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { ParkFormValues, TurbineTypeFormValues } from '@components/ux';
|
||||
|
||||
import { api } from '../api';
|
||||
import { WIND_ENDPOINTS } from './constants';
|
||||
import { Park, ParkTurbine, TurbineType } from './types';
|
||||
import { packParkFormValues, packTurbineTypeFormValues } from './utils';
|
||||
|
||||
export const getTurbineTypes = () => {
|
||||
return api.get<TurbineType[]>(WIND_ENDPOINTS.turbines);
|
||||
};
|
||||
|
||||
export const createTurbineTypes = (values: Partial<TurbineTypeFormValues>) => {
|
||||
return api.post(
|
||||
WIND_ENDPOINTS.turbineType,
|
||||
packTurbineTypeFormValues(values),
|
||||
);
|
||||
};
|
||||
|
||||
export const editTurbineTypes = (
|
||||
values: Partial<TurbineTypeFormValues>,
|
||||
id: number,
|
||||
) => {
|
||||
const url = `${WIND_ENDPOINTS.turbineType}/${id}`;
|
||||
return api.put(url, packTurbineTypeFormValues(values));
|
||||
};
|
||||
|
||||
export const deleteTurbineTypes = (id: number) => {
|
||||
const url = `${WIND_ENDPOINTS.turbineType}/${id}`;
|
||||
return api.delete(url);
|
||||
};
|
||||
|
||||
export const getParks = () => {
|
||||
return api.get<Park[]>(WIND_ENDPOINTS.parks);
|
||||
};
|
||||
|
||||
export const createPark = (values: Partial<ParkFormValues>) => {
|
||||
return api.post(WIND_ENDPOINTS.park, packParkFormValues(values));
|
||||
};
|
||||
|
||||
export const editPark = (values: Partial<ParkFormValues>, id: number) => {
|
||||
const url = `${WIND_ENDPOINTS.park}/${id}`;
|
||||
return api.put(url, packParkFormValues(values));
|
||||
};
|
||||
|
||||
export const getParkTurines = (id: number) => {
|
||||
const url = `${WIND_ENDPOINTS.parks}/${id}/turbines`;
|
||||
return api.get<ParkTurbine[]>(url);
|
||||
};
|
22
front/src/api/wind/types.ts
Normal file
22
front/src/api/wind/types.ts
Normal file
@ -0,0 +1,22 @@
|
||||
export type TurbineType = {
|
||||
id: number;
|
||||
name: string;
|
||||
height: number;
|
||||
bladeLength: number;
|
||||
};
|
||||
|
||||
export type Park = {
|
||||
id: number;
|
||||
name: string;
|
||||
centerLatitude: number;
|
||||
centerLongitude: number;
|
||||
};
|
||||
|
||||
export type ParkTurbine = {
|
||||
windParkId: number;
|
||||
turbineId: number;
|
||||
xOffset: number;
|
||||
yOffset: number;
|
||||
angle: number;
|
||||
comment: string;
|
||||
};
|
19
front/src/api/wind/utils.ts
Normal file
19
front/src/api/wind/utils.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { ParkFormValues, TurbineTypeFormValues } from '@components/ux';
|
||||
|
||||
export const packTurbineTypeFormValues = (
|
||||
values: Partial<TurbineTypeFormValues>,
|
||||
) => {
|
||||
return {
|
||||
Name: values.name ?? '',
|
||||
Height: parseInt(values.height ?? '0'),
|
||||
BladeLength: parseInt(values.bladeLength ?? '0'),
|
||||
};
|
||||
};
|
||||
|
||||
export const packParkFormValues = (values: Partial<ParkFormValues>) => {
|
||||
return {
|
||||
Name: values.name ?? '',
|
||||
CenterLatitude: parseInt(values.centerLatitude ?? '0'),
|
||||
CenterLongitude: parseInt(values.centerLongitude ?? '0'),
|
||||
};
|
||||
};
|
19
front/src/components/_func.scss
Normal file
19
front/src/components/_func.scss
Normal file
@ -0,0 +1,19 @@
|
||||
@function scale($values, $factor) {
|
||||
@if type-of($values) == 'list' {
|
||||
$m-values: ();
|
||||
@each $value in $values {
|
||||
$m-values: append($m-values, $value * $factor);
|
||||
}
|
||||
@return $m-values;
|
||||
} @else {
|
||||
@return nth($values, 1) * $factor;
|
||||
}
|
||||
}
|
||||
|
||||
@function m($values) {
|
||||
@return scale($values, 1.25);
|
||||
}
|
||||
|
||||
@function l($values) {
|
||||
@return scale($values, 1.5);
|
||||
}
|
@ -4,12 +4,12 @@
|
||||
--clr-primary: #4176FF;
|
||||
--clr-primary-o50: #3865DA80;
|
||||
--clr-primary-hover: #638FFF;
|
||||
--clr-primary-active: #3D68D7;
|
||||
--clr-primary-disabled: #3D68D7;
|
||||
--clr-on-primary: #FFFFFF;
|
||||
|
||||
--clr-secondary: #EAEAEA;
|
||||
--clr-secondary-hover: #EFEFEF;
|
||||
--clr-secondary-active: #E1E1E1;
|
||||
--clr-secondary-disabled: #E1E1E1;
|
||||
--clr-on-secondary: #0D0D0D;
|
||||
|
||||
--clr-layer-100: #EBEEF0;
|
||||
@ -36,12 +36,12 @@
|
||||
--clr-primary: #3865DA;
|
||||
--clr-primary-o50: #3865DA80;
|
||||
--clr-primary-hover: #4073F7;
|
||||
--clr-primary-active: #2A4DA7;
|
||||
--clr-primary-disabled: #2A4DA7;
|
||||
--clr-on-primary: #FFFFFF;
|
||||
|
||||
--clr-secondary: #3F3F3F;
|
||||
--clr-secondary-hover: #4D4D4D;
|
||||
--clr-secondary-active: #323232;
|
||||
--clr-secondary-disabled: #323232;
|
||||
--clr-on-secondary: #FFFFFF;
|
||||
|
||||
--clr-layer-100: #1B1B1B;
|
||||
|
@ -2,17 +2,27 @@ import './styles.scss';
|
||||
import '@public/fonts/styles.css';
|
||||
|
||||
import { MainLayout } from '@components/layouts';
|
||||
import { HomePage } from '@components/pages';
|
||||
import { ParksPage, TurbineTypesPage } from '@components/pages';
|
||||
import { ROUTES } from '@utils/route';
|
||||
import React from 'react';
|
||||
import { BrowserRouter, Route, Routes } from 'react-router-dom';
|
||||
import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<Routes>
|
||||
<Route element={<MainLayout />}>
|
||||
<Route path={'/'} element={<HomePage />} />
|
||||
<Route
|
||||
index
|
||||
element={<Navigate to={ROUTES.turbineTypes.path} replace />}
|
||||
/>
|
||||
<Route
|
||||
path={ROUTES.turbineTypes.path}
|
||||
element={<TurbineTypesPage />}
|
||||
/>
|
||||
<Route path={ROUTES.parks.path} element={<ParksPage />} />
|
||||
</Route>
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Header } from '@components/ux';
|
||||
import { Sidebar } from '@components/ux';
|
||||
import React from 'react';
|
||||
import { Outlet } from 'react-router-dom';
|
||||
|
||||
@ -7,9 +7,11 @@ import styles from './styles.module.scss';
|
||||
function MainLayout() {
|
||||
return (
|
||||
<div className={styles.mainLayout}>
|
||||
<Header />
|
||||
<Sidebar />
|
||||
<main className={styles.main}>
|
||||
<div className={styles.content}>
|
||||
<Outlet />
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
|
@ -2,12 +2,20 @@
|
||||
display: grid;
|
||||
height: 100%;
|
||||
grid-template:
|
||||
'header' auto
|
||||
'main' minmax(0, 1fr)
|
||||
/ minmax(0, 1fr);
|
||||
'sidebar main' minmax(0, 1fr)
|
||||
/ auto minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.main {
|
||||
display: flex;
|
||||
overflow: auto;
|
||||
height: 100%;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.content {
|
||||
display: grid;
|
||||
width: 1000px;
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
grid-template-rows: minmax(0, 1fr);
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
import { Heading, Paragraph } from '@components/ui';
|
||||
import { WindmillForm } from '@components/ux';
|
||||
import { WindmillFormResponse } from '@components/ux/windmill-form';
|
||||
import React, { useState } from 'react';
|
||||
|
||||
import styles from './styles.module.scss';
|
||||
|
||||
export function HomePage() {
|
||||
const [result, setResult] = useState<WindmillFormResponse | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const handleFormSuccess = (response: WindmillFormResponse) => {
|
||||
setResult(response);
|
||||
setError(null);
|
||||
};
|
||||
|
||||
const handleFormFail = (message: string) => {
|
||||
setError(message);
|
||||
setResult(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
<div className={styles.wrapperForm}>
|
||||
<WindmillForm onSuccess={handleFormSuccess} onFail={handleFormFail} />
|
||||
</div>
|
||||
<div className={styles.result}>
|
||||
<Heading tag="h3">Result</Heading>
|
||||
{result && (
|
||||
<>
|
||||
<div className={styles.power}>{result.power.join(' ')}</div>
|
||||
<div className={styles.image}>
|
||||
{result.image && <img src={result.image} alt="Image" />}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{error && <Paragraph>{error}</Paragraph>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
@ -1 +0,0 @@
|
||||
export { HomePage } from './component';
|
@ -1,41 +0,0 @@
|
||||
.page {
|
||||
display: grid;
|
||||
padding: 20px;
|
||||
gap: 20px;
|
||||
grid-template:
|
||||
'. form result .' auto
|
||||
/ auto minmax(0, 380px) minmax(0, 700px) auto;
|
||||
}
|
||||
|
||||
.wrapperForm {
|
||||
grid-area: form;
|
||||
}
|
||||
|
||||
.result {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
background-color: var(--clr-layer-200);
|
||||
box-shadow: 0px 1px 2px var(--clr-shadow-100);
|
||||
gap: 20px;
|
||||
grid-area: result;
|
||||
}
|
||||
|
||||
.image {
|
||||
width: 100%;
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
border-radius: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (width <= 1000px) {
|
||||
.page {
|
||||
grid-template:
|
||||
'form' auto
|
||||
'result' auto
|
||||
/ 1fr;
|
||||
}
|
||||
}
|
2
front/src/components/pages/index.ts
Normal file
2
front/src/components/pages/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './parks-page';
|
||||
export * from './turbine-types-page';
|
@ -1 +0,0 @@
|
||||
export { HomePage } from './home-page';
|
81
front/src/components/pages/parks-page/component.tsx
Normal file
81
front/src/components/pages/parks-page/component.tsx
Normal file
@ -0,0 +1,81 @@
|
||||
import { Button, Heading } from '@components/ui';
|
||||
import { DataGrid } from '@components/ui/data-grid';
|
||||
import { ParkModal } from '@components/ux';
|
||||
import { useRoute } from '@utils/route';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { getParks, Park } from 'src/api/wind';
|
||||
|
||||
import { columns } from './constants';
|
||||
import styles from './styles.module.scss';
|
||||
|
||||
export function ParksPage() {
|
||||
const [createModalOpen, setCreateModalOpen] = useState<boolean>(false);
|
||||
const [editModalOpen, setEditModalOpen] = useState<boolean>(false);
|
||||
const [parks, setParks] = useState<Park[]>([]);
|
||||
const [selected, setSelected] = useState<Park>(null);
|
||||
const route = useRoute();
|
||||
|
||||
const fetchParks = async () => {
|
||||
const res = await getParks();
|
||||
setParks(res.data ?? []);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchParks();
|
||||
}, []);
|
||||
|
||||
const handleCreateButtonClick = () => {
|
||||
setCreateModalOpen(true);
|
||||
};
|
||||
|
||||
const handleEditButtonClick = () => {
|
||||
setEditModalOpen(true);
|
||||
};
|
||||
|
||||
const handleParkSelect = (items: Park[]) => {
|
||||
setSelected(items[0] ?? null);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
<Heading tag="h1" className={styles.heading}>
|
||||
{route.title}
|
||||
</Heading>
|
||||
<div className={styles.actions}>
|
||||
<Button onClick={handleCreateButtonClick}>Create new</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={handleEditButtonClick}
|
||||
disabled={!selected}
|
||||
>
|
||||
Edit
|
||||
</Button>
|
||||
<Button variant="secondary" disabled={!selected}>
|
||||
Delete
|
||||
</Button>
|
||||
</div>
|
||||
<div className={styles.dataGridWrapper}>
|
||||
<DataGrid
|
||||
items={parks}
|
||||
columns={columns}
|
||||
getItemKey={({ id }) => String(id)}
|
||||
selectedItems={selected ? [selected] : []}
|
||||
onItemsSelect={handleParkSelect}
|
||||
multiselect={false}
|
||||
/>
|
||||
</div>
|
||||
<ParkModal
|
||||
park={null}
|
||||
open={createModalOpen}
|
||||
onClose={() => setCreateModalOpen(false)}
|
||||
onSuccess={fetchParks}
|
||||
/>
|
||||
<ParkModal
|
||||
park={selected}
|
||||
open={editModalOpen}
|
||||
onClose={() => setEditModalOpen(false)}
|
||||
onSuccess={fetchParks}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
8
front/src/components/pages/parks-page/constants.ts
Normal file
8
front/src/components/pages/parks-page/constants.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { DataGridColumnConfig } from '@components/ui/data-grid/types';
|
||||
import { Park } from 'src/api/wind';
|
||||
|
||||
export const columns: DataGridColumnConfig<Park>[] = [
|
||||
{ name: 'Name', getText: (t) => t.name, flex: '2' },
|
||||
{ name: 'Center latitude', getText: (t) => String(t.centerLatitude) },
|
||||
{ name: 'Center longitude', getText: (t) => String(t.centerLongitude) },
|
||||
];
|
20
front/src/components/pages/parks-page/styles.module.scss
Normal file
20
front/src/components/pages/parks-page/styles.module.scss
Normal file
@ -0,0 +1,20 @@
|
||||
.page {
|
||||
display: grid;
|
||||
padding: 40px 20px 20px;
|
||||
gap: 20px;
|
||||
grid-template-rows: auto auto minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.dataGridWrapper {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
padding: 10px;
|
||||
border: 1px solid var(--clr-border-100);
|
||||
border-radius: 10px;
|
||||
background-color: var(--clr-layer-200);
|
||||
box-shadow: 0px 1px 2px var(--clr-shadow-100);
|
||||
gap: 10px;
|
||||
}
|
90
front/src/components/pages/turbine-types-page/component.tsx
Normal file
90
front/src/components/pages/turbine-types-page/component.tsx
Normal file
@ -0,0 +1,90 @@
|
||||
import { Button, Heading } from '@components/ui';
|
||||
import { DataGrid } from '@components/ui/data-grid';
|
||||
import { TurbineTypeModal } from '@components/ux';
|
||||
import { useRoute } from '@utils/route';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { deleteTurbineTypes, getTurbineTypes, TurbineType } from 'src/api/wind';
|
||||
|
||||
import { columns } from './constants';
|
||||
import styles from './styles.module.scss';
|
||||
|
||||
export function TurbineTypesPage() {
|
||||
const [createModalOpen, setCreateModalOpen] = useState<boolean>(false);
|
||||
const [editModalOpen, setEditModalOpen] = useState<boolean>(false);
|
||||
const [turbineTypes, setTurbineTypes] = useState<TurbineType[]>([]);
|
||||
const [selected, setSelected] = useState<TurbineType>(null);
|
||||
const route = useRoute();
|
||||
|
||||
const fetchTurbineTypes = async () => {
|
||||
const res = await getTurbineTypes();
|
||||
setTurbineTypes(res.data ?? []);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchTurbineTypes();
|
||||
}, []);
|
||||
|
||||
const handleCreateButtonClick = () => {
|
||||
setCreateModalOpen(true);
|
||||
};
|
||||
|
||||
const handleEditButtonClick = () => {
|
||||
setEditModalOpen(true);
|
||||
};
|
||||
|
||||
const handleDeleteButtonClick = async () => {
|
||||
await deleteTurbineTypes(selected.id);
|
||||
fetchTurbineTypes();
|
||||
};
|
||||
|
||||
const handleTurbineTypeSelect = (items: TurbineType[]) => {
|
||||
setSelected(items[0] ?? null);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
<Heading tag="h1" className={styles.heading}>
|
||||
{route.title}
|
||||
</Heading>
|
||||
<div className={styles.actions}>
|
||||
<Button onClick={handleCreateButtonClick}>Create new</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={handleEditButtonClick}
|
||||
disabled={!selected}
|
||||
>
|
||||
Edit
|
||||
</Button>
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={handleDeleteButtonClick}
|
||||
disabled={!selected}
|
||||
>
|
||||
Delete
|
||||
</Button>
|
||||
</div>
|
||||
<div className={styles.dataGridWrapper}>
|
||||
<DataGrid
|
||||
items={turbineTypes}
|
||||
columns={columns}
|
||||
getItemKey={({ id }) => String(id)}
|
||||
selectedItems={selected ? [selected] : []}
|
||||
onItemsSelect={handleTurbineTypeSelect}
|
||||
multiselect={false}
|
||||
/>
|
||||
</div>
|
||||
<TurbineTypeModal
|
||||
turbineType={null}
|
||||
open={createModalOpen}
|
||||
onClose={() => setCreateModalOpen(false)}
|
||||
onSuccess={fetchTurbineTypes}
|
||||
/>
|
||||
<TurbineTypeModal
|
||||
turbineType={selected}
|
||||
open={editModalOpen}
|
||||
onClose={() => setEditModalOpen(false)}
|
||||
onSuccess={fetchTurbineTypes}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
import { DataGridColumnConfig } from '@components/ui/data-grid/types';
|
||||
import { TurbineType } from 'src/api/wind';
|
||||
|
||||
export const columns: DataGridColumnConfig<TurbineType>[] = [
|
||||
{ name: 'Name', getText: (t) => t.name, flex: '2' },
|
||||
{ name: 'Height', getText: (t) => String(t.height) },
|
||||
{ name: 'Blade length', getText: (t) => String(t.bladeLength) },
|
||||
];
|
1
front/src/components/pages/turbine-types-page/index.ts
Normal file
1
front/src/components/pages/turbine-types-page/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './component';
|
@ -0,0 +1,20 @@
|
||||
.page {
|
||||
display: grid;
|
||||
padding: 40px 20px 20px;
|
||||
gap: 20px;
|
||||
grid-template-rows: auto auto minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.dataGridWrapper {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
padding: 10px;
|
||||
border: 1px solid var(--clr-border-100);
|
||||
border-radius: 10px;
|
||||
background-color: var(--clr-layer-200);
|
||||
box-shadow: 0px 1px 2px var(--clr-shadow-100);
|
||||
gap: 10px;
|
||||
}
|
@ -9,21 +9,17 @@
|
||||
@keyframes fadein {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: scale(0.9) translateY(-30px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: scale(1) translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fadeout {
|
||||
from {
|
||||
opacity: 1;
|
||||
transform: scale(1) translateY(0);
|
||||
}
|
||||
to {
|
||||
opacity: 0;
|
||||
transform: scale(0.9) translateY(-30px);
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,3 @@
|
||||
export * from './fade';
|
||||
export * from './ripple';
|
||||
export * from './slide';
|
||||
|
@ -1,68 +1,64 @@
|
||||
import React, {
|
||||
ForwardedRef,
|
||||
forwardRef,
|
||||
useImperativeHandle,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import clsx from 'clsx';
|
||||
import React, { useRef } from 'react';
|
||||
|
||||
import { RippleWave } from './parts/ripple-wave';
|
||||
import styles from './styles.module.scss';
|
||||
import { RippleProps } from './types';
|
||||
import { calcRippleWaveStyle } from './utils';
|
||||
|
||||
export function RippleInner(
|
||||
props: RippleProps,
|
||||
ref: ForwardedRef<HTMLDivElement>,
|
||||
) {
|
||||
export function Ripple() {
|
||||
const rippleRef = useRef<HTMLDivElement | null>(null);
|
||||
const [waves, setWaves] = useState<React.JSX.Element[]>([]);
|
||||
const [isTouch, setIsTouch] = useState(false);
|
||||
|
||||
useImperativeHandle(ref, () => rippleRef.current, []);
|
||||
const clean = () => {
|
||||
document.removeEventListener('touchend', clean);
|
||||
document.removeEventListener('mouseup', clean);
|
||||
if (!rippleRef.current) {
|
||||
return;
|
||||
}
|
||||
const { lastChild: wave } = rippleRef.current;
|
||||
if (!wave || !(wave instanceof HTMLElement)) {
|
||||
return;
|
||||
}
|
||||
wave.dataset.isMouseReleased = 'true';
|
||||
if (wave.dataset.isAnimationComplete) {
|
||||
wave.classList.replace(styles.visible, styles.invisible);
|
||||
}
|
||||
};
|
||||
|
||||
const handleWaveOnDone = () => {
|
||||
setWaves((prev) => prev.slice(1));
|
||||
const handleAnimationEnd = (event: AnimationEvent) => {
|
||||
const { target: wave, animationName } = event;
|
||||
if (!(wave instanceof HTMLElement)) {
|
||||
return;
|
||||
}
|
||||
if (animationName === styles.fadein) {
|
||||
wave.dataset.isAnimationComplete = 'true';
|
||||
if (wave.dataset.isMouseReleased) {
|
||||
wave.classList.replace(styles.visible, styles.invisible);
|
||||
}
|
||||
} else {
|
||||
wave.remove();
|
||||
}
|
||||
};
|
||||
|
||||
const addWave = (x: number, y: number) => {
|
||||
const wave = document.createElement('div');
|
||||
const style = calcRippleWaveStyle(x, y, rippleRef.current);
|
||||
const wave = (
|
||||
<RippleWave
|
||||
key={new Date().getTime()}
|
||||
style={style}
|
||||
onDone={handleWaveOnDone}
|
||||
/>
|
||||
);
|
||||
setWaves([...waves, wave]);
|
||||
Object.assign(wave.style, style);
|
||||
wave.className = clsx(styles.wave, styles.visible);
|
||||
wave.addEventListener('animationend', handleAnimationEnd);
|
||||
rippleRef.current.appendChild(wave);
|
||||
document.addEventListener('touchend', clean);
|
||||
document.addEventListener('mouseup', clean);
|
||||
};
|
||||
|
||||
const handleMouseDown = (event: React.MouseEvent) => {
|
||||
if (isTouch) {
|
||||
return;
|
||||
}
|
||||
const handlePointerDown = (event: React.MouseEvent) => {
|
||||
const { pageX, pageY } = event;
|
||||
addWave(pageX, pageY);
|
||||
};
|
||||
|
||||
const handleTouchStart = (event: React.TouchEvent) => {
|
||||
setIsTouch(true);
|
||||
const { touches, changedTouches } = event;
|
||||
const { pageX, pageY } = touches[0] ?? changedTouches[0];
|
||||
addWave(pageX, pageY);
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={rippleRef}
|
||||
className={styles.ripple}
|
||||
onMouseDown={handleMouseDown}
|
||||
onTouchStart={handleTouchStart}
|
||||
{...props}
|
||||
>
|
||||
{waves}
|
||||
</div>
|
||||
ref={rippleRef}
|
||||
onPointerDown={handlePointerDown}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export const Ripple = forwardRef(RippleInner);
|
||||
|
@ -1,39 +0,0 @@
|
||||
import clsx from 'clsx';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
import styles from './style.module.scss';
|
||||
import { RippleWaveProps } from './types';
|
||||
|
||||
export function RippleWave({ style, onDone }: RippleWaveProps) {
|
||||
const [isMouseUp, setIsMouseUp] = useState(false);
|
||||
const [isAnimationEnd, setIsAnimationEnd] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const mouseUpListener = () => setIsMouseUp(true);
|
||||
document.addEventListener('mouseup', mouseUpListener, { once: true });
|
||||
document.addEventListener('touchend', mouseUpListener, { once: true });
|
||||
}, []);
|
||||
|
||||
const visible = !isMouseUp || !isAnimationEnd;
|
||||
|
||||
const className = clsx(
|
||||
styles.wave,
|
||||
visible ? styles.visible : styles.invisible,
|
||||
);
|
||||
|
||||
const handleAnimationEnd = (event: React.AnimationEvent) => {
|
||||
if (event.animationName === styles.fadein) {
|
||||
setIsAnimationEnd(true);
|
||||
} else {
|
||||
onDone();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={className}
|
||||
onAnimationEnd={handleAnimationEnd}
|
||||
style={style}
|
||||
/>
|
||||
);
|
||||
}
|
@ -1 +0,0 @@
|
||||
export { RippleWave } from './component';
|
@ -1,33 +0,0 @@
|
||||
.wave {
|
||||
position: absolute;
|
||||
border-radius: 100%;
|
||||
background-color: var(--clr-ripple);
|
||||
}
|
||||
|
||||
.visible {
|
||||
animation: fadein 0.3s linear;
|
||||
}
|
||||
|
||||
.invisible {
|
||||
animation: fadeout 0.3s linear forwards;
|
||||
}
|
||||
|
||||
@keyframes fadein {
|
||||
from {
|
||||
opacity: 0;
|
||||
scale: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
scale: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fadeout {
|
||||
from {
|
||||
opacity: 1;
|
||||
}
|
||||
to {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
import { CSSProperties } from 'react';
|
||||
|
||||
export type RippleWaveProps = {
|
||||
style: CSSProperties;
|
||||
onDone: () => void;
|
||||
};
|
@ -5,3 +5,37 @@
|
||||
width: 200%;
|
||||
height: 200%;
|
||||
}
|
||||
|
||||
.wave {
|
||||
position: absolute;
|
||||
border-radius: 100%;
|
||||
background-color: var(--clr-ripple);
|
||||
}
|
||||
|
||||
.visible {
|
||||
animation: fadein 0.3s linear;
|
||||
}
|
||||
|
||||
.invisible {
|
||||
animation: fadeout 0.3s linear forwards;
|
||||
}
|
||||
|
||||
@keyframes fadein {
|
||||
from {
|
||||
opacity: 0;
|
||||
scale: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
scale: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fadeout {
|
||||
from {
|
||||
opacity: 1;
|
||||
}
|
||||
to {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
export type RippleProps = {} & React.ComponentProps<'div'>;
|
@ -1,3 +1,4 @@
|
||||
import { px } from '@utils/css';
|
||||
import { CSSProperties } from 'react';
|
||||
|
||||
export const calcRippleWaveStyle = (
|
||||
@ -8,7 +9,7 @@ export const calcRippleWaveStyle = (
|
||||
const wrapperRect = ripple.getBoundingClientRect();
|
||||
const diameter = Math.max(wrapperRect.width, wrapperRect.height);
|
||||
const radius = diameter / 2;
|
||||
const left = x - wrapperRect.left - radius;
|
||||
const top = y - wrapperRect.top - radius;
|
||||
return { left, top, width: diameter, height: diameter };
|
||||
const left = px(x - wrapperRect.left - radius);
|
||||
const top = px(y - wrapperRect.top - radius);
|
||||
return { left, top, width: px(diameter), height: px(diameter) };
|
||||
};
|
||||
|
58
front/src/components/ui/animation/slide/component.tsx
Normal file
58
front/src/components/ui/animation/slide/component.tsx
Normal file
@ -0,0 +1,58 @@
|
||||
import clsx from 'clsx';
|
||||
import React, { ForwardedRef, forwardRef, useEffect, useState } from 'react';
|
||||
|
||||
import styles from './styles.module.scss';
|
||||
import { SlideProps } from './types';
|
||||
|
||||
export function SlideInner(
|
||||
{
|
||||
visible,
|
||||
duration = 200,
|
||||
className,
|
||||
style,
|
||||
...props
|
||||
}: Omit<SlideProps, 'ref'>,
|
||||
ref: ForwardedRef<HTMLDivElement>,
|
||||
) {
|
||||
const [visibleInner, setVisibleInner] = useState<boolean>(visible);
|
||||
|
||||
const classNames = clsx(
|
||||
styles.slide,
|
||||
{ [styles.invisible]: !visible },
|
||||
className,
|
||||
);
|
||||
|
||||
const inlineStyle = {
|
||||
...style,
|
||||
'--animation-duration': `${duration}ms`,
|
||||
} as React.CSSProperties;
|
||||
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
setVisibleInner(true);
|
||||
return;
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
const handleAnimationEnd = (event: React.AnimationEvent) => {
|
||||
if (event.animationName === styles.fadeout) {
|
||||
setVisibleInner(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (!visibleInner) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames}
|
||||
ref={ref}
|
||||
style={inlineStyle}
|
||||
onAnimationEnd={handleAnimationEnd}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export const Slide = forwardRef(SlideInner);
|
1
front/src/components/ui/animation/slide/index.ts
Normal file
1
front/src/components/ui/animation/slide/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './component';
|
29
front/src/components/ui/animation/slide/styles.module.scss
Normal file
29
front/src/components/ui/animation/slide/styles.module.scss
Normal file
@ -0,0 +1,29 @@
|
||||
.slide {
|
||||
animation: fadein var(--animation-duration);
|
||||
}
|
||||
|
||||
.invisible {
|
||||
animation: fadeout var(--animation-duration) forwards ease-in-out;
|
||||
}
|
||||
|
||||
@keyframes fadein {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: scale(0.9) translateY(-30px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: scale(1) translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fadeout {
|
||||
from {
|
||||
opacity: 1;
|
||||
transform: scale(1) translateY(0);
|
||||
}
|
||||
to {
|
||||
opacity: 0;
|
||||
transform: scale(0.9) translateY(-30px);
|
||||
}
|
||||
}
|
4
front/src/components/ui/animation/slide/types.ts
Normal file
4
front/src/components/ui/animation/slide/types.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export type SlideProps = {
|
||||
visible: boolean;
|
||||
duration?: number;
|
||||
} & React.ComponentProps<'div'>;
|
124
front/src/components/ui/autocomplete/component.tsx
Normal file
124
front/src/components/ui/autocomplete/component.tsx
Normal file
@ -0,0 +1,124 @@
|
||||
import ArrowDownIcon from '@public/images/svg/arrow-down.svg';
|
||||
import { useMissClick } from '@utils/miss-click';
|
||||
import clsx from 'clsx';
|
||||
import React, {
|
||||
ForwardedRef,
|
||||
forwardRef,
|
||||
useImperativeHandle,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
|
||||
import { Menu } from '../menu';
|
||||
import { Popover } from '../popover';
|
||||
import { TextInput } from '../text-input';
|
||||
import styles from './styles.module.scss';
|
||||
import { AutocompleteProps } from './types';
|
||||
|
||||
function AutocompleteInner<T>(
|
||||
{
|
||||
options,
|
||||
value,
|
||||
getOptionKey,
|
||||
getOptionLabel,
|
||||
onChange,
|
||||
scale = 'm',
|
||||
label = {},
|
||||
name,
|
||||
id,
|
||||
className,
|
||||
...props
|
||||
}: Omit<AutocompleteProps<T>, 'ref'>,
|
||||
ref: ForwardedRef<HTMLDivElement>,
|
||||
) {
|
||||
const autocompleteRef = useRef<HTMLDivElement | null>(null);
|
||||
const menuRef = useRef<HTMLUListElement | null>(null);
|
||||
const inputWrapperRef = useRef<HTMLDivElement | null>(null);
|
||||
const [menuVisible, setMenuVisible] = useState<boolean>(false);
|
||||
const [text, setText] = useState<string>('');
|
||||
|
||||
useImperativeHandle(ref, () => autocompleteRef.current, []);
|
||||
|
||||
useMissClick(
|
||||
[autocompleteRef, menuRef],
|
||||
() => setMenuVisible(false),
|
||||
menuVisible,
|
||||
);
|
||||
|
||||
const autocompleteClassName = clsx(
|
||||
styles.autocomplete,
|
||||
styles[scale],
|
||||
{ [styles.menuVisible]: menuVisible },
|
||||
className,
|
||||
);
|
||||
|
||||
const filteredOptions = options.filter((option) => {
|
||||
const label = getOptionLabel(option).toLocaleLowerCase();
|
||||
const raw = text.trim().toLocaleLowerCase();
|
||||
return label.includes(raw);
|
||||
});
|
||||
|
||||
const handleInputClick = () => {
|
||||
setMenuVisible(!menuVisible);
|
||||
};
|
||||
|
||||
const handleMenuSelect = (option: T) => {
|
||||
setMenuVisible(false);
|
||||
onChange?.(option);
|
||||
setText('');
|
||||
};
|
||||
|
||||
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const { value } = event.target;
|
||||
setText(value);
|
||||
const option = options.find((option) => {
|
||||
const label = getOptionLabel(option).toLocaleLowerCase();
|
||||
const raw = value.toLocaleLowerCase();
|
||||
return label === raw;
|
||||
});
|
||||
onChange?.(option ?? null);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={autocompleteClassName} ref={autocompleteRef} {...props}>
|
||||
<TextInput
|
||||
value={value ? getOptionLabel(value) : text}
|
||||
onClick={handleInputClick}
|
||||
scale={scale}
|
||||
label={label}
|
||||
name={name}
|
||||
id={id}
|
||||
wrapper={{ ref: inputWrapperRef }}
|
||||
onChange={handleInputChange}
|
||||
rightNode={
|
||||
<div className={styles.iconBox}>
|
||||
<ArrowDownIcon className={styles.icon} />
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
<Popover
|
||||
visible={menuVisible}
|
||||
anchorRef={autocompleteRef}
|
||||
position="bottom"
|
||||
horizontalAlign="stretch"
|
||||
flip
|
||||
element={
|
||||
<div className={styles.menuWrapper}>
|
||||
<Menu
|
||||
options={filteredOptions}
|
||||
selected={value}
|
||||
getOptionKey={getOptionKey}
|
||||
getOptionLabel={getOptionLabel}
|
||||
onSelect={handleMenuSelect}
|
||||
ref={menuRef}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export const Autocomplete = forwardRef(AutocompleteInner) as <T>(
|
||||
props: AutocompleteProps<T>,
|
||||
) => ReturnType<typeof AutocompleteInner>;
|
3
front/src/components/ui/autocomplete/index.ts
Normal file
3
front/src/components/ui/autocomplete/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export { Autocomplete } from './component';
|
||||
export { AutocompletePreview } from './preview';
|
||||
export { type AutocompleteProps } from './types';
|
44
front/src/components/ui/autocomplete/preview.tsx
Normal file
44
front/src/components/ui/autocomplete/preview.tsx
Normal file
@ -0,0 +1,44 @@
|
||||
import { PreviewArticle } from '@components/ui/preview';
|
||||
import React, { useState } from 'react';
|
||||
|
||||
import { Autocomplete } from './component';
|
||||
|
||||
export function AutocompletePreview() {
|
||||
const [selectValue, setSelectValue] = useState<string>();
|
||||
const options = ['Orange', 'Banana', 'Apple', 'Avocado'];
|
||||
|
||||
return (
|
||||
<PreviewArticle title="Autocomplete">
|
||||
<Autocomplete
|
||||
options={options}
|
||||
getOptionKey={(o) => o}
|
||||
getOptionLabel={(o) => o}
|
||||
label={{ text: 'Select your favorite fruit' }}
|
||||
scale="s"
|
||||
value={selectValue}
|
||||
onChange={(o) => setSelectValue(o)}
|
||||
name="fruit"
|
||||
/>
|
||||
<Autocomplete
|
||||
options={options}
|
||||
getOptionKey={(o) => o}
|
||||
getOptionLabel={(o) => o}
|
||||
label={{ text: 'Select your favorite fruit' }}
|
||||
scale="m"
|
||||
value={selectValue}
|
||||
onChange={(o) => setSelectValue(o)}
|
||||
name="fruit"
|
||||
/>
|
||||
<Autocomplete
|
||||
options={options}
|
||||
getOptionKey={(o) => o}
|
||||
getOptionLabel={(o) => o}
|
||||
label={{ text: 'Select your favorite fruit' }}
|
||||
scale="l"
|
||||
value={selectValue}
|
||||
onChange={(o) => setSelectValue(o)}
|
||||
name="fruit"
|
||||
/>
|
||||
</PreviewArticle>
|
||||
);
|
||||
}
|
62
front/src/components/ui/autocomplete/styles.module.scss
Normal file
62
front/src/components/ui/autocomplete/styles.module.scss
Normal file
@ -0,0 +1,62 @@
|
||||
@use '@components/func.scss' as f;
|
||||
|
||||
.autocomplete {
|
||||
position: relative;
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
.icon {
|
||||
fill: var(--clr-text-100);
|
||||
transition: all var(--td-100) ease-in-out;
|
||||
}
|
||||
|
||||
.fade {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.menuVisible {
|
||||
.icon {
|
||||
rotate: 180deg;
|
||||
}
|
||||
}
|
||||
|
||||
.menuWrapper {
|
||||
padding: 5px 0;
|
||||
}
|
||||
|
||||
$padding-right: 7px;
|
||||
$size: 10px;
|
||||
|
||||
.s {
|
||||
.iconBox {
|
||||
padding-right: $padding-right;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: $size;
|
||||
height: $size;
|
||||
}
|
||||
}
|
||||
|
||||
.m {
|
||||
.iconBox {
|
||||
padding-right: f.m($padding-right);
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: f.m($size);
|
||||
height: f.m($size);
|
||||
}
|
||||
}
|
||||
|
||||
.l {
|
||||
.iconBox {
|
||||
padding-right: f.l($padding-right);
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: f.l($size);
|
||||
height: f.l($size);
|
||||
}
|
||||
}
|
14
front/src/components/ui/autocomplete/types.ts
Normal file
14
front/src/components/ui/autocomplete/types.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { LabelProps } from '../label';
|
||||
import { Scale } from '../types';
|
||||
|
||||
export type AutocompleteProps<T> = {
|
||||
options: T[];
|
||||
value?: T;
|
||||
getOptionKey: (option: T) => React.Key;
|
||||
getOptionLabel: (option: T) => string;
|
||||
onChange?: (option: T) => void;
|
||||
scale?: Scale;
|
||||
label?: LabelProps;
|
||||
name?: string;
|
||||
id?: string;
|
||||
} & Omit<React.ComponentProps<'div'>, 'onChange'>;
|
@ -1,7 +1,7 @@
|
||||
import clsx from 'clsx';
|
||||
import React from 'react';
|
||||
|
||||
import { Ripple } from '../animation';
|
||||
import { Ripple } from '../animation/ripple/component';
|
||||
import { Comet } from '../comet';
|
||||
import { RawButton } from '../raw';
|
||||
import { COMET_VARIANT_MAP } from './constants';
|
||||
|
@ -1,3 +1,5 @@
|
||||
@use '@components/func.scss' as f;
|
||||
|
||||
.button {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
@ -39,8 +41,9 @@
|
||||
background-color: var(--clr-primary-hover);
|
||||
}
|
||||
|
||||
&:disabled,
|
||||
&.pending {
|
||||
background-color: var(--clr-primary-active);
|
||||
background-color: var(--clr-primary-disabled);
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,25 +55,30 @@
|
||||
background-color: var(--clr-secondary-hover);
|
||||
}
|
||||
|
||||
&:disabled,
|
||||
&.pending {
|
||||
background-color: var(--clr-secondary-active);
|
||||
background-color: var(--clr-secondary-disabled);
|
||||
}
|
||||
}
|
||||
|
||||
$padding: 10px 16px;
|
||||
$border-radius: 8px;
|
||||
$font-size: 12px;
|
||||
|
||||
.s {
|
||||
padding: 10px 16px;
|
||||
border-radius: 8px;
|
||||
font-size: 12px;
|
||||
padding: $padding;
|
||||
border-radius: $border-radius;
|
||||
font-size: $font-size;
|
||||
}
|
||||
|
||||
.m {
|
||||
padding: 14px 20px;
|
||||
border-radius: 10px;
|
||||
font-size: 16px;
|
||||
padding: f.m($padding);
|
||||
border-radius: f.m($border-radius);
|
||||
font-size: f.m($font-size);
|
||||
}
|
||||
|
||||
.l {
|
||||
padding: 18px 24px;
|
||||
border-radius: 12px;
|
||||
font-size: 20px;
|
||||
padding: f.l($padding);
|
||||
border-radius: f.l($border-radius);
|
||||
font-size: f.l($font-size);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React, { ForwardedRef, forwardRef, useEffect, useState } from 'react';
|
||||
|
||||
import { CalendarDays } from './parts';
|
||||
import { CalendarDays } from './components';
|
||||
import { CalendarProps } from './types';
|
||||
|
||||
function CalendarInner(
|
||||
|
@ -33,7 +33,7 @@ export function CalendarDays({
|
||||
}, [date, min, max]);
|
||||
|
||||
const handleChange = (newValue: string) => {
|
||||
onChange?.(newValue);
|
||||
onChange(newValue);
|
||||
};
|
||||
|
||||
return (
|
@ -40,19 +40,12 @@
|
||||
justify-content: center;
|
||||
border-radius: 10px;
|
||||
color: var(--clr-text-100);
|
||||
transition: all var(--td-100) ease-in-out;
|
||||
|
||||
&:not(:disabled) {
|
||||
cursor: pointer;
|
||||
transition: all var(--td-100) ease-in-out;
|
||||
|
||||
&:hover {
|
||||
background-color: var(--clr-layer-300-hover);
|
||||
}
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
color: var(--clr-text-100);
|
||||
}
|
||||
}
|
||||
|
||||
.currentMonthDay {
|
@ -9,7 +9,7 @@ export type CalendarDay = {
|
||||
|
||||
export type CalendarDaysProps = {
|
||||
value?: string;
|
||||
onChange?: (value: string) => void;
|
||||
onChange: (value: string) => void;
|
||||
min: Date | null;
|
||||
max: Date | null;
|
||||
date: Date;
|
@ -1,11 +1,18 @@
|
||||
import { dateToInputString } from '@utils/date';
|
||||
|
||||
import { CalendarDay, GetCalendarDaysParams } from './types';
|
||||
|
||||
const addDays = (date: Date, days: number) => {
|
||||
date.setDate(date.getDate() + days);
|
||||
};
|
||||
|
||||
function dateToInputString(date: Date) {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}T${hours}:${minutes}`;
|
||||
}
|
||||
|
||||
const daysAreEqual = (date1: Date, date2: Date) => {
|
||||
return (
|
||||
date1.getDate() === date2.getDate() &&
|
@ -1,6 +1,6 @@
|
||||
export type CalendarProps = {
|
||||
value?: string;
|
||||
onChange?: (value: string) => void;
|
||||
onChange: (value: string) => void;
|
||||
min: Date | null;
|
||||
max: Date | null;
|
||||
} & Omit<React.ComponentProps<'div'>, 'onChange'>;
|
||||
|
@ -1,22 +1,26 @@
|
||||
@use '@components/func.scss' as f;
|
||||
|
||||
.checkBoxGroup {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
$margin-bottom: 4px;
|
||||
|
||||
.s {
|
||||
.label {
|
||||
margin-bottom: 3px;
|
||||
margin-bottom: $margin-bottom;
|
||||
}
|
||||
}
|
||||
|
||||
.m {
|
||||
.label {
|
||||
margin-bottom: 5px;
|
||||
margin-bottom: f.m($margin-bottom);
|
||||
}
|
||||
}
|
||||
|
||||
.l {
|
||||
.label {
|
||||
margin-bottom: 7px;
|
||||
margin-bottom: f.l($margin-bottom);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import CheckIcon from '@public/images/svg/check.svg';
|
||||
import clsx from 'clsx';
|
||||
import React, { ForwardedRef, forwardRef } from 'react';
|
||||
|
||||
import { Ripple } from '../animation';
|
||||
import { Ripple } from '../animation/ripple/component';
|
||||
import { Label, LabelProps } from '../label';
|
||||
import { RawInput } from '../raw';
|
||||
import styles from './styles.module.scss';
|
||||
|
@ -1,8 +1,11 @@
|
||||
@use '@components/func.scss' as f;
|
||||
|
||||
.wrapper {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
border-radius: 100%;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
|
||||
&:hover {
|
||||
.checkbox {
|
||||
@ -42,7 +45,7 @@
|
||||
.checkbox {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
border: 1px solid var(--clr-border-200);
|
||||
border: 2px solid var(--clr-border-200);
|
||||
background-color: var(--clr-layer-300);
|
||||
box-shadow: 0px 2px 2px var(--clr-shadow-200);
|
||||
transition: all var(--td-100) ease-in-out;
|
||||
@ -54,35 +57,40 @@
|
||||
transition: all var(--td-100) ease-in-out;
|
||||
}
|
||||
|
||||
$padding-outer: 4px;
|
||||
$size: 16px;
|
||||
$padding-inner: 2px;
|
||||
$border-radius: 5px;
|
||||
|
||||
.s {
|
||||
padding: 3px;
|
||||
padding: $padding-outer;
|
||||
|
||||
.checkbox {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
padding: 2px;
|
||||
border-radius: 5px;
|
||||
width: $size;
|
||||
height: $size;
|
||||
padding: $padding-inner;
|
||||
border-radius: $border-radius;
|
||||
}
|
||||
}
|
||||
|
||||
.m {
|
||||
padding: 5px;
|
||||
padding: f.m($padding-outer);
|
||||
|
||||
.checkbox {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
padding: 3px;
|
||||
border-radius: 6px;
|
||||
width: f.m($size);
|
||||
height: f.m($size);
|
||||
padding: f.m($padding-inner);
|
||||
border-radius: f.m($border-radius);
|
||||
}
|
||||
}
|
||||
|
||||
.l {
|
||||
padding: 7px;
|
||||
padding: f.l($padding-outer);
|
||||
|
||||
.checkbox {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
padding: 4px;
|
||||
border-radius: 7px;
|
||||
width: f.l($size);
|
||||
height: f.l($size);
|
||||
padding: f.l($padding-inner);
|
||||
border-radius: f.l($border-radius);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
@use '@components/func.scss' as f;
|
||||
|
||||
.comet {
|
||||
border-radius: 50%;
|
||||
animation: spinner-comet 1s infinite linear;
|
||||
@ -9,23 +11,37 @@
|
||||
}
|
||||
}
|
||||
|
||||
$size: 12px;
|
||||
$offset: 1.75px;
|
||||
|
||||
.s {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
mask: radial-gradient(farthest-side, #0000 calc(100% - 2px), #000 0);
|
||||
width: $size;
|
||||
height: $size;
|
||||
mask: radial-gradient(
|
||||
farthest-side,
|
||||
#0000 calc(100% - $offset),
|
||||
#000 0
|
||||
);
|
||||
}
|
||||
|
||||
.m {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
mask: radial-gradient(farthest-side, #0000 calc(100% - 2.5px), #000 0);
|
||||
width: f.m($size);
|
||||
height: f.m($size);
|
||||
mask: radial-gradient(
|
||||
farthest-side,
|
||||
#0000 calc(100% - f.m($offset)),
|
||||
#000 0
|
||||
);
|
||||
}
|
||||
|
||||
.l {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
mask: radial-gradient(farthest-side, #0000 calc(100% - 3px), #000 0);
|
||||
}
|
||||
width: f.l($size);
|
||||
height: f.l($size);
|
||||
mask: radial-gradient(
|
||||
farthest-side,
|
||||
#0000 calc(100% - f.l($offset)),
|
||||
#000 0
|
||||
);}
|
||||
|
||||
.onPrimary {
|
||||
background: conic-gradient(#0000 10%, var(--clr-on-primary));
|
||||
|
74
front/src/components/ui/data-grid/component.tsx
Normal file
74
front/src/components/ui/data-grid/component.tsx
Normal file
@ -0,0 +1,74 @@
|
||||
import { arrayToObject } from '@utils/array';
|
||||
import clsx from 'clsx';
|
||||
import React, { useMemo, useState } from 'react';
|
||||
|
||||
import { DataGridHeader, DataGridRow } from './components';
|
||||
import styles from './styles.module.scss';
|
||||
import { DataGridProps } from './types';
|
||||
|
||||
export function DataGrid<T>({
|
||||
items,
|
||||
columns,
|
||||
getItemKey,
|
||||
className,
|
||||
selectedItems,
|
||||
onItemsSelect,
|
||||
multiselect = true,
|
||||
...props
|
||||
}: DataGridProps<T>) {
|
||||
const [allRowsSelected, setAllRowsSelected] = useState<boolean>(false);
|
||||
|
||||
const selectedItemsMap = useMemo(
|
||||
() => arrayToObject(selectedItems, (i) => getItemKey(i)),
|
||||
[selectedItems],
|
||||
);
|
||||
|
||||
const handleSelectAllRows = () => {
|
||||
if (!multiselect) {
|
||||
return;
|
||||
}
|
||||
setAllRowsSelected(!allRowsSelected);
|
||||
if (allRowsSelected) {
|
||||
onItemsSelect([]);
|
||||
} else {
|
||||
onItemsSelect([...items]);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRowSelect = (item: T) => {
|
||||
setAllRowsSelected(false);
|
||||
const key = getItemKey(item);
|
||||
const selected = selectedItemsMap[key];
|
||||
if (!multiselect) {
|
||||
onItemsSelect(selected ? [] : [item]);
|
||||
} else {
|
||||
onItemsSelect(
|
||||
selected
|
||||
? selectedItems.filter((i) => key !== getItemKey(i))
|
||||
: [...selectedItems, item],
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={clsx(styles.dataGrid, className)} {...props}>
|
||||
<DataGridHeader
|
||||
columns={columns}
|
||||
allRowsSelected={allRowsSelected}
|
||||
onSelectAllRows={handleSelectAllRows}
|
||||
/>
|
||||
{items.map((item) => {
|
||||
const key = getItemKey(item);
|
||||
return (
|
||||
<DataGridRow
|
||||
object={item}
|
||||
columns={columns}
|
||||
selected={selectedItemsMap[key] ? true : false}
|
||||
onSelect={() => handleRowSelect(item)}
|
||||
key={key}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
import { Ripple } from '@components/ui/animation';
|
||||
import { Checkbox } from '@components/ui/checkbox';
|
||||
import { RawButton } from '@components/ui/raw';
|
||||
import { Span } from '@components/ui/span';
|
||||
import ArrowUpIcon from '@public/images/svg/arrow-up.svg';
|
||||
import clsx from 'clsx';
|
||||
import React, { useState } from 'react';
|
||||
|
||||
import { DataGridSort } from '../../types';
|
||||
import styles from './styles.module.scss';
|
||||
import { DataGridHeaderProps } from './types';
|
||||
|
||||
export function DataGridHeader<T>({
|
||||
columns,
|
||||
allRowsSelected,
|
||||
onSelectAllRows,
|
||||
}: DataGridHeaderProps<T>) {
|
||||
const [sort, setSort] = useState<DataGridSort>({ order: 'asc', column: '' });
|
||||
|
||||
const handleSortButtonClick = (column: string) => {
|
||||
if (column === sort.column) {
|
||||
if (sort.order === 'asc') {
|
||||
setSort({ order: 'desc', column });
|
||||
} else {
|
||||
setSort({ order: 'desc', column: '' });
|
||||
}
|
||||
} else {
|
||||
setSort({ order: 'asc', column });
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<header className={styles.header}>
|
||||
<Checkbox
|
||||
checked={allRowsSelected}
|
||||
onChange={onSelectAllRows}
|
||||
label={{ className: styles.checkboxLabel }}
|
||||
/>
|
||||
{columns.map((column) => {
|
||||
const isActive = sort.column === column.name;
|
||||
const cellClassName = clsx(styles.cell, {
|
||||
[styles.activeCell]: isActive,
|
||||
[styles.desc]: isActive && sort.order === 'desc',
|
||||
});
|
||||
return (
|
||||
<RawButton
|
||||
style={{ flex: column.flex }}
|
||||
className={cellClassName}
|
||||
key={column.name}
|
||||
onClick={() => handleSortButtonClick(column.name)}
|
||||
>
|
||||
<Span color="t300" className={styles.name}>
|
||||
{column.name}
|
||||
</Span>
|
||||
<ArrowUpIcon className={styles.icon} />
|
||||
<Ripple />
|
||||
</RawButton>
|
||||
);
|
||||
})}
|
||||
</header>
|
||||
);
|
||||
}
|
@ -0,0 +1 @@
|
||||
export * from './component';
|
@ -0,0 +1,54 @@
|
||||
.header {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.checkboxLabel {
|
||||
padding: 10px;
|
||||
border: solid 1px var(--clr-border-100);
|
||||
background-color: var(--clr-layer-300);
|
||||
}
|
||||
|
||||
.cell {
|
||||
position: relative;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
flex: 1;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
border: solid 1px var(--clr-border-100);
|
||||
background-color: var(--clr-layer-300);
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
gap: 10px;
|
||||
transition: all var(--td-100) ease-in-out;
|
||||
|
||||
&:hover {
|
||||
background-color: var(--clr-layer-300-hover);
|
||||
}
|
||||
}
|
||||
|
||||
.name {
|
||||
overflow: hidden;
|
||||
flex-shrink: 1;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
flex-shrink: 0;
|
||||
fill: transparent;
|
||||
transition: all var(--td-100) ease-in-out;
|
||||
}
|
||||
|
||||
.activeCell {
|
||||
.icon {
|
||||
fill: var(--clr-text-200);
|
||||
}
|
||||
}
|
||||
|
||||
.desc {
|
||||
.icon {
|
||||
rotate: 180deg;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
import { DataGridColumnConfig } from '../../types';
|
||||
|
||||
export type DataGridHeaderProps<T> = {
|
||||
columns: DataGridColumnConfig<T>[];
|
||||
allRowsSelected: boolean;
|
||||
onSelectAllRows: () => void;
|
||||
};
|
@ -0,0 +1,32 @@
|
||||
import { Checkbox } from '@components/ui/checkbox';
|
||||
import { Span } from '@components/ui/span';
|
||||
import React from 'react';
|
||||
|
||||
import styles from './styles.module.scss';
|
||||
import { DataGridRowProps } from './types';
|
||||
|
||||
export function DataGridRow<T>({
|
||||
object,
|
||||
columns,
|
||||
selected,
|
||||
onSelect,
|
||||
}: DataGridRowProps<T>) {
|
||||
return (
|
||||
<div className={styles.row}>
|
||||
<Checkbox
|
||||
checked={selected}
|
||||
label={{ className: styles.checkboxLabel }}
|
||||
onChange={onSelect}
|
||||
/>
|
||||
{columns.map((column) => (
|
||||
<div
|
||||
className={styles.cell}
|
||||
style={{ flex: column.flex }}
|
||||
key={column.name}
|
||||
>
|
||||
<Span color="t200">{column.getText(object)}</Span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
@ -0,0 +1 @@
|
||||
export * from './component';
|
@ -0,0 +1,20 @@
|
||||
.row {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.checkboxLabel {
|
||||
padding: 10px;
|
||||
border: solid 1px var(--clr-border-100);
|
||||
background-color: var(--clr-layer-200);
|
||||
}
|
||||
|
||||
.cell {
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
flex: 1 0 0;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
border: solid 1px var(--clr-border-100);
|
||||
background-color: var(--clr-layer-200);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
import { DataGridColumnConfig } from '../../types';
|
||||
|
||||
export type DataGridRowProps<T> = {
|
||||
object: T;
|
||||
columns: DataGridColumnConfig<T>[];
|
||||
selected: boolean;
|
||||
onSelect: () => void;
|
||||
};
|
2
front/src/components/ui/data-grid/components/index.ts
Normal file
2
front/src/components/ui/data-grid/components/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './DataGridHeader';
|
||||
export * from './DataGridRow';
|
2
front/src/components/ui/data-grid/index.ts
Normal file
2
front/src/components/ui/data-grid/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './component';
|
||||
export * from './preview';
|
28
front/src/components/ui/data-grid/preview.tsx
Normal file
28
front/src/components/ui/data-grid/preview.tsx
Normal file
@ -0,0 +1,28 @@
|
||||
import { PreviewArticle } from '@components/ui/preview';
|
||||
import React from 'react';
|
||||
|
||||
import { DataGrid } from './component';
|
||||
import { Cat, DataGridColumnConfig } from './types';
|
||||
|
||||
export function DataGridPreview() {
|
||||
const items: Cat[] = [
|
||||
{ name: 'Luna', breed: 'British Shorthair', color: 'Gray', age: '2' },
|
||||
{ name: 'Simba', breed: 'Siamese', color: 'Cream', age: '1' },
|
||||
{ name: 'Bella', breed: 'Maine Coon', color: 'Brown Tabby', age: '3' },
|
||||
{ name: 'Oliver', breed: 'Persian', color: 'White', age: '4' },
|
||||
{ name: 'Milo', breed: 'Sphynx', color: 'Pink', age: '2' },
|
||||
];
|
||||
|
||||
const columns: DataGridColumnConfig<Cat>[] = [
|
||||
{ name: 'Name', getText: (cat) => cat.name, flex: '2' },
|
||||
{ name: 'Breed', getText: (cat) => cat.breed },
|
||||
{ name: 'Age', getText: (cat) => cat.age },
|
||||
{ name: 'Color', getText: (cat) => cat.color },
|
||||
];
|
||||
|
||||
return (
|
||||
<PreviewArticle title="DataGrid">
|
||||
<DataGrid style={{ width: '100%' }} items={items} columns={columns} />
|
||||
</PreviewArticle>
|
||||
);
|
||||
}
|
4
front/src/components/ui/data-grid/styles.module.scss
Normal file
4
front/src/components/ui/data-grid/styles.module.scss
Normal file
@ -0,0 +1,4 @@
|
||||
.dataGrid {
|
||||
border-radius: 10px;
|
||||
box-shadow: 0px 2px 2px var(--clr-shadow-200);
|
||||
}
|
27
front/src/components/ui/data-grid/types.ts
Normal file
27
front/src/components/ui/data-grid/types.ts
Normal file
@ -0,0 +1,27 @@
|
||||
export type DataGridColumnConfig<T> = {
|
||||
name: string;
|
||||
getText: (object: T) => string;
|
||||
sortable?: boolean;
|
||||
flex?: string;
|
||||
};
|
||||
|
||||
export type DataGridSort = {
|
||||
order: 'asc' | 'desc';
|
||||
column: string;
|
||||
};
|
||||
|
||||
export type DataGridProps<T> = {
|
||||
items: T[];
|
||||
columns: DataGridColumnConfig<T>[];
|
||||
getItemKey: (object: T) => string;
|
||||
selectedItems: T[];
|
||||
onItemsSelect: (selectedItems: T[]) => void;
|
||||
multiselect?: boolean;
|
||||
} & React.ComponentPropsWithoutRef<'div'>;
|
||||
|
||||
export type Cat = {
|
||||
name: string;
|
||||
breed: string;
|
||||
age: string;
|
||||
color: string;
|
||||
};
|
@ -1,5 +1,4 @@
|
||||
import CalendarIcon from '@public/images/svg/calendar.svg';
|
||||
import { px } from '@utils/css';
|
||||
import { useMissClick } from '@utils/miss-click';
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
|
||||
@ -48,6 +47,14 @@ export function DateInput({
|
||||
setCalendarVisible(!calendarVisible);
|
||||
};
|
||||
|
||||
const handleCalendarButtonMouseDown = (event: React.MouseEvent) => {
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
const handleCalendarButtonMouseUp = (event: React.MouseEvent) => {
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const newDirtyDate = inputToDirtyDate(event.target.value);
|
||||
if (newDirtyDate.length === 10) {
|
||||
@ -58,42 +65,19 @@ export function DateInput({
|
||||
(!minDate || date >= minDate) &&
|
||||
(!maxDate || date <= maxDate)
|
||||
) {
|
||||
onChange?.(newValue);
|
||||
onChange(newValue);
|
||||
} else {
|
||||
onChange?.('');
|
||||
onChange('');
|
||||
}
|
||||
}
|
||||
setDirtyDate(newDirtyDate);
|
||||
};
|
||||
|
||||
const handleCalendarChange = (newValue: string) => {
|
||||
onChange?.(newValue);
|
||||
onChange(newValue);
|
||||
setCalendarVisible(false);
|
||||
};
|
||||
|
||||
const calcPopoverStyles = (calendarRect: DOMRect) => {
|
||||
if (calendarRect === null) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const inputWrapperRect = inputWrapperRef.current.getBoundingClientRect();
|
||||
const { left, bottom, top } = inputWrapperRect;
|
||||
|
||||
const rightSpace = window.innerWidth - left;
|
||||
const rightOverflow = calendarRect.width - rightSpace;
|
||||
const bottomSpace = window.innerHeight - bottom;
|
||||
|
||||
const popoverLeft = rightOverflow <= 0 ? left : left - rightOverflow;
|
||||
|
||||
const popoverTop =
|
||||
bottomSpace >= calendarRect.height ? bottom : top - calendarRect.height;
|
||||
|
||||
return {
|
||||
left: px(popoverLeft),
|
||||
top: px(popoverTop),
|
||||
};
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.wrapper} ref={wrapperRef}>
|
||||
<TextInput
|
||||
@ -104,7 +88,12 @@ export function DateInput({
|
||||
wrapper={{ ref: inputWrapperRef }}
|
||||
rightNode={
|
||||
<>
|
||||
<IconButton scale={scale} onClick={handleCalendarButtonClick}>
|
||||
<IconButton
|
||||
scale={scale}
|
||||
onClick={handleCalendarButtonClick}
|
||||
onMouseDown={handleCalendarButtonMouseDown}
|
||||
onMouseUp={handleCalendarButtonMouseUp}
|
||||
>
|
||||
<CalendarIcon />
|
||||
</IconButton>
|
||||
{rightNode}
|
||||
@ -113,7 +102,10 @@ export function DateInput({
|
||||
/>
|
||||
<Popover
|
||||
visible={calendarVisible}
|
||||
calcStyles={calcPopoverStyles}
|
||||
anchorRef={wrapperRef}
|
||||
position="bottom"
|
||||
horizontalAlign="center"
|
||||
flip
|
||||
element={
|
||||
<div className={styles.calendarWrapper} ref={calendarWrapperRef}>
|
||||
<Calendar
|
||||
|
@ -2,7 +2,7 @@ import { TextInputProps } from '../text-input';
|
||||
|
||||
export type DateInputProps = {
|
||||
value?: string;
|
||||
onChange?: (value: string) => void;
|
||||
onChange: (value: string) => void;
|
||||
max?: string;
|
||||
min?: string;
|
||||
} & Omit<TextInputProps, 'type' | 'value' | 'onChange'>;
|
||||
|
78
front/src/components/ui/file-uploader/component.tsx
Normal file
78
front/src/components/ui/file-uploader/component.tsx
Normal file
@ -0,0 +1,78 @@
|
||||
import UploadIcon from '@public/images/svg/upload.svg';
|
||||
import { getFileExtension } from '@utils/file';
|
||||
import clsx from 'clsx';
|
||||
import React, { useRef } from 'react';
|
||||
|
||||
import { Ripple } from '../animation';
|
||||
import { Label } from '../label';
|
||||
import { RawButton, RawInput } from '../raw';
|
||||
import { Span } from '../span';
|
||||
import styles from './style.module.scss';
|
||||
import { FileUploaderProps } from './types';
|
||||
|
||||
export function FileUploader({
|
||||
extensions,
|
||||
onChange,
|
||||
scale = 'm',
|
||||
label = {},
|
||||
input = {},
|
||||
...props
|
||||
}: FileUploaderProps) {
|
||||
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||
const uploaderClassName = clsx(styles.uploader, styles[scale]);
|
||||
|
||||
const handleChange = (files: FileList) => {
|
||||
if (!files || !onChange) {
|
||||
return;
|
||||
}
|
||||
const array = Array.from(files);
|
||||
const filtered = extensions
|
||||
? array.filter((file) => extensions.includes(getFileExtension(file)))
|
||||
: array;
|
||||
onChange(filtered);
|
||||
};
|
||||
|
||||
const handleButtonClick = () => {
|
||||
inputRef.current.click();
|
||||
};
|
||||
|
||||
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
handleChange(event.target.files);
|
||||
};
|
||||
|
||||
const handleDragOver = (event: React.DragEvent) => {
|
||||
event.preventDefault();
|
||||
event.dataTransfer.dropEffect = 'copy';
|
||||
};
|
||||
|
||||
const handleDrop = (event: React.DragEvent) => {
|
||||
event.preventDefault();
|
||||
handleChange(event.dataTransfer.files);
|
||||
};
|
||||
|
||||
return (
|
||||
<Label scale={scale} {...label}>
|
||||
<RawButton
|
||||
className={uploaderClassName}
|
||||
onClick={handleButtonClick}
|
||||
onDragOver={handleDragOver}
|
||||
onDrop={handleDrop}
|
||||
{...props}
|
||||
>
|
||||
<UploadIcon className={styles.icon} />
|
||||
<Span color="t300" scale={scale}>
|
||||
Drag and drop file here or click to upload
|
||||
</Span>
|
||||
<RawInput
|
||||
type="file"
|
||||
className={styles.input}
|
||||
ref={inputRef}
|
||||
onChange={handleInputChange}
|
||||
accept={extensions && extensions.map((ext) => `.${ext}`).join(',')}
|
||||
{...input}
|
||||
/>
|
||||
<Ripple />
|
||||
</RawButton>
|
||||
</Label>
|
||||
);
|
||||
}
|
1
front/src/components/ui/file-uploader/index.ts
Normal file
1
front/src/components/ui/file-uploader/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export { FileUploader } from './component';
|
14
front/src/components/ui/file-uploader/preview.tsx
Normal file
14
front/src/components/ui/file-uploader/preview.tsx
Normal file
@ -0,0 +1,14 @@
|
||||
import { PreviewArticle } from '@components/ui/preview';
|
||||
import React from 'react';
|
||||
|
||||
import { FileUploader } from './component';
|
||||
|
||||
export function FileUploaderPreview() {
|
||||
return (
|
||||
<PreviewArticle title="FileUploader">
|
||||
<FileUploader scale="s" label={{ text: 'File uploader' }} />
|
||||
<FileUploader scale="m" label={{ text: 'File uploader' }} />
|
||||
<FileUploader scale="l" label={{ text: 'File uploader' }} />
|
||||
</PreviewArticle>
|
||||
);
|
||||
}
|
68
front/src/components/ui/file-uploader/style.module.scss
Normal file
68
front/src/components/ui/file-uploader/style.module.scss
Normal file
@ -0,0 +1,68 @@
|
||||
@use '@components/func.scss' as f;
|
||||
|
||||
.uploader {
|
||||
position: relative;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
border: 1px dashed var(--clr-border-200);
|
||||
background-color: var(--clr-layer-300);
|
||||
box-shadow: 0px 2px 2px var(--clr-shadow-100);
|
||||
cursor: pointer;
|
||||
transition: all var(--td-100) ease-in-out;
|
||||
|
||||
&:not(.wrapperFocus):hover {
|
||||
background-color: var(--clr-layer-300-hover);
|
||||
}
|
||||
}
|
||||
|
||||
.input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.icon {
|
||||
fill: var(--clr-text-100);
|
||||
}
|
||||
|
||||
$padding: 10px 16px;
|
||||
$border-radius: 8px;
|
||||
$font-size: 12px;
|
||||
$icon-size: 24px;
|
||||
$gap: 5px;
|
||||
|
||||
.s {
|
||||
padding: $padding;
|
||||
border-radius: $border-radius;
|
||||
font-size: $font-size;
|
||||
gap: $gap;
|
||||
|
||||
.icon {
|
||||
width: $icon-size;
|
||||
height: $icon-size;
|
||||
}
|
||||
}
|
||||
|
||||
.m {
|
||||
padding: f.m($padding);
|
||||
border-radius: f.m($border-radius);
|
||||
font-size: f.m($font-size);
|
||||
gap: f.m($gap);
|
||||
|
||||
.icon {
|
||||
width: f.m($icon-size);
|
||||
height: f.m($icon-size);
|
||||
}
|
||||
}
|
||||
|
||||
.l {
|
||||
padding: f.l($padding);
|
||||
border-radius: f.l($border-radius);
|
||||
font-size: f.l($font-size);
|
||||
gap: f.l($gap);
|
||||
|
||||
.icon {
|
||||
width: f.l($icon-size);
|
||||
height: f.l($icon-size);
|
||||
}
|
||||
}
|
11
front/src/components/ui/file-uploader/types.ts
Normal file
11
front/src/components/ui/file-uploader/types.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { LabelProps } from '../label';
|
||||
import { RawInputProps } from '../raw';
|
||||
import { Scale } from '../types';
|
||||
|
||||
export type FileUploaderProps = {
|
||||
extensions?: string[];
|
||||
onChange?: (value: File[]) => void;
|
||||
scale?: Scale;
|
||||
label?: LabelProps;
|
||||
input?: Omit<RawInputProps, 'type'>;
|
||||
} & Omit<React.ComponentPropsWithoutRef<'button'>, 'onChange'>;
|
@ -1,3 +1,5 @@
|
||||
@use '@components/func.scss' as f;
|
||||
|
||||
.button {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
@ -22,20 +24,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
$size: 26px;
|
||||
$padding: 4px;
|
||||
|
||||
.s {
|
||||
width: 27px;
|
||||
height: 27px;
|
||||
padding: 4px;
|
||||
width: $size;
|
||||
height: $size;
|
||||
padding: $padding;
|
||||
}
|
||||
|
||||
.m {
|
||||
width: 35px;
|
||||
height: 35px;
|
||||
padding: 6px;
|
||||
width: f.m($size);
|
||||
height: f.m($size);
|
||||
padding: f.m($padding);
|
||||
}
|
||||
|
||||
.l {
|
||||
width: 43px;
|
||||
height: 43px;
|
||||
padding: 8px;
|
||||
width: f.l($size);
|
||||
height: f.l($size);
|
||||
padding: f.l($padding);
|
||||
}
|
||||
|
40
front/src/components/ui/image-file-manager/component.tsx
Normal file
40
front/src/components/ui/image-file-manager/component.tsx
Normal file
@ -0,0 +1,40 @@
|
||||
import clsx from 'clsx';
|
||||
import React from 'react';
|
||||
|
||||
import { FileUploader } from '../file-uploader';
|
||||
import { ImageViewer } from '../image-viewer';
|
||||
import styles from './styles.module.scss';
|
||||
import { ImageFileManagerProps } from './types';
|
||||
|
||||
export function ImageFileManager({
|
||||
value,
|
||||
onChange,
|
||||
scale = 'm',
|
||||
label = {},
|
||||
}: ImageFileManagerProps) {
|
||||
const managerClassName = clsx(styles.manager, styles[scale]);
|
||||
|
||||
const handleFileUploaderChange = (files: File[]) => {
|
||||
const file = files[0];
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
onChange?.(file);
|
||||
};
|
||||
|
||||
const handleClear = () => {
|
||||
onChange?.(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={managerClassName}>
|
||||
<FileUploader
|
||||
scale={scale}
|
||||
label={label}
|
||||
onChange={handleFileUploaderChange}
|
||||
extensions={['png', 'jpg', 'jpeg']}
|
||||
/>
|
||||
<ImageViewer file={value} scale={scale} onClear={handleClear} />
|
||||
</div>
|
||||
);
|
||||
}
|
1
front/src/components/ui/image-file-manager/index.ts
Normal file
1
front/src/components/ui/image-file-manager/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export { ImageFileManager } from './component';
|
31
front/src/components/ui/image-file-manager/preview.tsx
Normal file
31
front/src/components/ui/image-file-manager/preview.tsx
Normal file
@ -0,0 +1,31 @@
|
||||
import { PreviewArticle } from '@components/ui/preview';
|
||||
import React, { useState } from 'react';
|
||||
|
||||
import { ImageFileManager } from './component';
|
||||
|
||||
export function ImageFileManagerPreview() {
|
||||
const [value, setValue] = useState<File>(null);
|
||||
|
||||
return (
|
||||
<PreviewArticle title="ImageFileManager">
|
||||
<ImageFileManager
|
||||
scale="s"
|
||||
label={{ text: 'Image uploader' }}
|
||||
value={value}
|
||||
onChange={setValue}
|
||||
/>
|
||||
<ImageFileManager
|
||||
scale="m"
|
||||
label={{ text: 'Image uploader' }}
|
||||
value={value}
|
||||
onChange={setValue}
|
||||
/>
|
||||
<ImageFileManager
|
||||
scale="l"
|
||||
label={{ text: 'Image uploader' }}
|
||||
value={value}
|
||||
onChange={setValue}
|
||||
/>
|
||||
</PreviewArticle>
|
||||
);
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
@use '@components/func.scss' as f;
|
||||
|
||||
.manager {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
|
||||
$gap: 12px;
|
||||
|
||||
.s {
|
||||
gap: $gap;
|
||||
}
|
||||
|
||||
.m {
|
||||
gap: f.m($gap);
|
||||
}
|
||||
|
||||
.l {
|
||||
gap: f.l($gap);
|
||||
}
|
9
front/src/components/ui/image-file-manager/types.ts
Normal file
9
front/src/components/ui/image-file-manager/types.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { LabelProps } from '../label';
|
||||
import { Scale } from '../types';
|
||||
|
||||
export type ImageFileManagerProps = {
|
||||
value?: File | null;
|
||||
onChange?: (value: File | null) => void;
|
||||
scale?: Scale;
|
||||
label?: LabelProps;
|
||||
} & Omit<React.ComponentPropsWithoutRef<'div'>, 'onChange'>;
|
32
front/src/components/ui/image-viewer/component.tsx
Normal file
32
front/src/components/ui/image-viewer/component.tsx
Normal file
@ -0,0 +1,32 @@
|
||||
import DeleteIcon from '@public/images/svg/delete.svg';
|
||||
import { formatFileSize } from '@utils/file';
|
||||
import clsx from 'clsx';
|
||||
import React from 'react';
|
||||
|
||||
import { IconButton } from '../icon-button';
|
||||
import { Span } from '../span';
|
||||
import styles from './styles.module.scss';
|
||||
import { ImageViewerProps } from './types';
|
||||
|
||||
export function ImageViewer({ file, scale = 'm', onClear }: ImageViewerProps) {
|
||||
const viewerClassName = clsx(styles.viewer, styles[scale]);
|
||||
return (
|
||||
<div className={viewerClassName}>
|
||||
{file ? (
|
||||
<>
|
||||
<img className={styles.image} src={URL.createObjectURL(file)} />
|
||||
<footer className={styles.footer}>
|
||||
<Span scale={scale}>{formatFileSize(file.size)}</Span>
|
||||
<IconButton scale={scale} onClick={onClear}>
|
||||
<DeleteIcon />
|
||||
</IconButton>
|
||||
</footer>
|
||||
</>
|
||||
) : (
|
||||
<div className={styles.placeholder}>
|
||||
<Span scale={scale}>File not uploaded</Span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
1
front/src/components/ui/image-viewer/index.ts
Normal file
1
front/src/components/ui/image-viewer/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export { ImageViewer } from './component';
|
56
front/src/components/ui/image-viewer/styles.module.scss
Normal file
56
front/src/components/ui/image-viewer/styles.module.scss
Normal file
@ -0,0 +1,56 @@
|
||||
@use '@components/func.scss' as f;
|
||||
|
||||
.viewer {
|
||||
display: grid;
|
||||
overflow: hidden;
|
||||
box-shadow: 0px 2px 2px var(--clr-shadow-100);
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
background-color: var(--clr-layer-300);
|
||||
}
|
||||
|
||||
.image {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
.footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
background-color: var(--clr-layer-300);
|
||||
}
|
||||
|
||||
$padding: 10px 16px;
|
||||
$border-radius: 8px;
|
||||
|
||||
.s {
|
||||
border-radius: $border-radius;
|
||||
|
||||
.placeholder,
|
||||
.footer {
|
||||
padding: $padding;
|
||||
}
|
||||
}
|
||||
|
||||
.m {
|
||||
border-radius: f.m($border-radius);
|
||||
|
||||
.placeholder,
|
||||
.footer {
|
||||
padding: f.m($padding);
|
||||
}
|
||||
}
|
||||
|
||||
.l {
|
||||
border-radius: f.l($border-radius);
|
||||
|
||||
.placeholder,
|
||||
.footer {
|
||||
padding: f.l($padding);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user