-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from JulienR1/features/better-icon-selector
Better icon selector
- Loading branch information
Showing
7 changed files
with
165 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package handlers | ||
|
||
import ( | ||
"JulienR1/moneymanager2/server/internal/services" | ||
"net/http" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
type IconHandler struct { | ||
service *services.IconService | ||
} | ||
|
||
func MakeIconHandler(s *services.IconService) IconHandler { | ||
return IconHandler{service: s} | ||
} | ||
|
||
func (handler *IconHandler) GetIcons(c *fiber.Ctx) error { | ||
icons, err := handler.service.GetIcons() | ||
if err != nil { | ||
return c.SendStatus(http.StatusInternalServerError) | ||
} | ||
return c.Status(http.StatusOK).JSON(icons) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package services | ||
|
||
import ( | ||
"JulienR1/moneymanager2/server/internal/repositories" | ||
"errors" | ||
) | ||
|
||
type IconService struct { | ||
repository *repositories.IconRepository | ||
} | ||
|
||
func MakeIconService(r *repositories.IconRepository) IconService { | ||
return IconService{repository: r} | ||
} | ||
|
||
func (service *IconService) GetIcons() ([]string, error) { | ||
icons, err := service.repository.FindAvailableIcons() | ||
if err != nil { | ||
return []string{}, errors.New("could not find icons") | ||
} | ||
return icons, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,92 @@ | ||
import { Icon, IconProps } from "@ui/icon"; | ||
import { Component, JSX, Show, createUniqueId } from "solid-js"; | ||
import { Component, JSX, ParentProps, Show, children, createUniqueId } from "solid-js"; | ||
import { FieldError } from "./field-error"; | ||
import { useForm } from "./form"; | ||
|
||
export type InputProps = Omit< | ||
JSX.InputHTMLAttributes<HTMLInputElement>, | ||
"oninput" | "onInput" | ||
> & { | ||
export type InputProps = Omit<JSX.InputHTMLAttributes<HTMLInputElement>, "oninput" | "onInput"> & { | ||
onInput?: JSX.InputEventHandler<HTMLInputElement, InputEvent>; | ||
} & WrapperProps; | ||
|
||
export type SelectProps = Omit<JSX.InputEventHandlerUnion<HTMLSelectElement, InputEvent>, "oninput" | "onInput"> & { | ||
onInput?: JSX.InputEventHandler<HTMLSelectElement, InputEvent>; | ||
placeholder?: string; | ||
} & WrapperProps; | ||
|
||
type WrapperProps = ParentProps<{ | ||
id: string; | ||
label: string; | ||
name: string; | ||
leftIcon?: IconProps; | ||
rightIcon?: IconProps; | ||
onInput?: JSX.InputEventHandler<HTMLInputElement, InputEvent>; | ||
}; | ||
|
||
export const Input: Component<InputProps> = (props) => { | ||
const { validateForm } = useForm(); | ||
|
||
const handleInput: JSX.InputEventHandler<HTMLInputElement, InputEvent> = ( | ||
e, | ||
) => { | ||
validateForm(); | ||
props.onInput?.(e); | ||
}; | ||
|
||
const id = props.id + createUniqueId(); | ||
}>; | ||
|
||
const Wrapper: Component<WrapperProps> = (props) => { | ||
return ( | ||
<div class="py-2"> | ||
<label | ||
for={id} | ||
class="flex items-center rounded-lg bg-white shadow shadow-gray-400 focus-within:shadow-lg" | ||
> | ||
<label for={props.id} class="flex items-center rounded-lg bg-white shadow shadow-gray-400 focus-within:shadow-lg"> | ||
<Show when={props.leftIcon}> | ||
<Icon | ||
{...props.leftIcon!} | ||
class={"ml-2 " + props.leftIcon?.class ?? ""} | ||
size="lg" | ||
mdSize="xl" | ||
/> | ||
<Icon {...props.leftIcon!} class={"ml-2 " + props.leftIcon?.class ?? ""} size="lg" mdSize="xl" /> | ||
</Show> | ||
|
||
<div class="w-full"> | ||
<p class="translate-y-1 px-2 text-xs font-semibold text-gray-500"> | ||
{props.label} | ||
</p> | ||
<input | ||
{...props} | ||
id={id} | ||
onInput={handleInput} | ||
class="w-full rounded-lg p-1 pt-0 text-xs font-semibold text-black focus-visible:outline-none md:p-2 md:text-sm" | ||
/> | ||
<p class="translate-y-1 px-2 text-xs font-semibold text-gray-500">{props.label}</p> | ||
{props.children} | ||
</div> | ||
|
||
<Show when={props.rightIcon}> | ||
<Icon | ||
{...props.rightIcon!} | ||
class={"mr-2 " + props.rightIcon?.class ?? ""} | ||
/> | ||
<Icon {...props.rightIcon!} class={"mr-2 " + props.rightIcon?.class ?? ""} /> | ||
</Show> | ||
</label> | ||
|
||
<FieldError name={props.name} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export const Input: Component<InputProps> = (props) => { | ||
const { validateForm } = useForm(); | ||
const id = props.id + createUniqueId(); | ||
|
||
const handleInput: JSX.InputEventHandler<HTMLInputElement, InputEvent> = (e) => { | ||
validateForm(); | ||
props.onInput?.(e); | ||
}; | ||
|
||
return ( | ||
<Wrapper {...props} id={id}> | ||
<input | ||
{...props} | ||
id={id} | ||
onInput={handleInput} | ||
class="w-full rounded-lg p-1 pt-0 text-xs font-semibold text-black focus-visible:outline-none md:p-2 md:text-sm" | ||
/> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export const Select: Component<SelectProps> = (props) => { | ||
const { validateForm } = useForm(); | ||
const id = props.id + createUniqueId(); | ||
const c = children(() => props.children); | ||
|
||
const handleInput: JSX.InputEventHandler<HTMLSelectElement, InputEvent> = (e) => { | ||
validateForm(); | ||
props.onInput?.(e); | ||
}; | ||
|
||
return ( | ||
<Wrapper {...props} id={id}> | ||
<select | ||
{...props} | ||
id={id} | ||
onInput={handleInput} | ||
class="w-full rounded-lg p-1 pt-0 text-xs font-semibold text-black focus-visible:outline-none md:p-2 md:text-sm" | ||
> | ||
<Show when={props.placeholder && props.placeholder.length > 0}> | ||
<option>{props.placeholder}</option> | ||
</Show> | ||
{c()} | ||
</select> | ||
</Wrapper> | ||
); | ||
}; |