forked from MetaCubeX/metacubexd
-
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.
feat(modals): add modal component (MetaCubeX#268)
* feat: add modal component * feat: add modal component * fix: proxies page arrow button problem * fix: button radius problem * feat: add modal component * feat: add modal component --------- Signed-off-by: Alpha <61853980+AlphaGHX@users.noreply.github.com>
- Loading branch information
Showing
14 changed files
with
161 additions
and
175 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
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,50 +1,34 @@ | ||
import { IconX } from '@tabler/icons-solidjs' | ||
import { IconNetwork } from '@tabler/icons-solidjs' | ||
import { Component, Show } from 'solid-js' | ||
import { MODAL } from '~/constants' | ||
import { Modal } from '~/components' | ||
import { useI18n } from '~/i18n' | ||
import { allConnections } from '~/signals' | ||
import { Button } from './Button' | ||
|
||
export const ConnectionsTableDetailsModal: Component<{ | ||
ref?: (el: HTMLDialogElement) => void | ||
selectedConnectionID?: string | ||
}> = (props) => { | ||
const modalID = MODAL.CONNECTIONS_TABLE_DETAILS | ||
const [t] = useI18n() | ||
|
||
return ( | ||
<dialog id={modalID} class="modal modal-bottom sm:modal-middle"> | ||
<div class="modal-box"> | ||
<div class="sticky top-0 z-50 flex items-center justify-end"> | ||
<Button | ||
class="btn-circle btn-sm" | ||
onClick={() => { | ||
const modal = document.querySelector( | ||
`#${modalID}`, | ||
) as HTMLDialogElement | null | ||
|
||
modal?.close() | ||
}} | ||
> | ||
<IconX size={20} /> | ||
</Button> | ||
</div> | ||
|
||
<Show when={props.selectedConnectionID}> | ||
<pre> | ||
<code> | ||
{JSON.stringify( | ||
allConnections().find( | ||
({ id }) => id === props.selectedConnectionID, | ||
), | ||
null, | ||
2, | ||
)} | ||
</code> | ||
</pre> | ||
</Show> | ||
</div> | ||
|
||
<form method="dialog" class="modal-backdrop"> | ||
<button /> | ||
</form> | ||
</dialog> | ||
<Modal | ||
ref={(el) => props.ref?.(el)} | ||
icon={<IconNetwork size={24} />} | ||
title={t('connectionsDetails')} | ||
> | ||
<Show when={props.selectedConnectionID}> | ||
<pre> | ||
<code> | ||
{JSON.stringify( | ||
allConnections().find( | ||
({ id }) => id === props.selectedConnectionID, | ||
), | ||
null, | ||
2, | ||
)} | ||
</code> | ||
</pre> | ||
</Show> | ||
</Modal> | ||
) | ||
} |
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,53 @@ | ||
import { IconX } from '@tabler/icons-solidjs' | ||
import { JSX, ParentComponent, Show, children } from 'solid-js' | ||
import { twMerge } from 'tailwind-merge' | ||
import { Button } from '~/components' | ||
|
||
type Props = { | ||
ref?: (el: HTMLDialogElement) => void | ||
icon?: JSX.Element | ||
title?: JSX.Element | ||
action?: JSX.Element | ||
} | ||
|
||
const actionClass = | ||
'sticky bottom-0 z-50 flex items-center justify-end bg-base-100 bg-opacity-80 p-6 backdrop-blur' | ||
|
||
export const Modal: ParentComponent<Props> = (props) => { | ||
let dialogRef: HTMLDialogElement | undefined | ||
|
||
return ( | ||
<dialog | ||
ref={(el) => (dialogRef = el) && props.ref?.(el)} | ||
class="modal modal-bottom sm:modal-middle" | ||
> | ||
<div class="modal-box p-0" onContextMenu={(e) => e.preventDefault()}> | ||
<div class={twMerge(actionClass, 'top-0 justify-between')}> | ||
<div class="flex items-center gap-4 text-xl font-bold"> | ||
{props.icon} | ||
<span>{props.title}</span> | ||
</div> | ||
<Button | ||
class="btn-circle btn-sm" | ||
onClick={() => { | ||
dialogRef?.close() | ||
}} | ||
icon={<IconX size={20} />} | ||
/> | ||
</div> | ||
|
||
<div class="p-6 pt-3">{children(() => props.children)()}</div> | ||
|
||
<Show when={props.action}> | ||
<div class={actionClass}> | ||
<div class="flex justify-end gap-2">{props.action}</div> | ||
</div> | ||
</Show> | ||
</div> | ||
|
||
<form method="dialog" class="modal-backdrop"> | ||
<button /> | ||
</form> | ||
</dialog> | ||
) | ||
} |
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
Oops, something went wrong.