diff --git a/.eslintrc.json b/.eslintrc.json
index bce7836..91ed479 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -20,7 +20,7 @@
"react"
],
"rules": {
- // "@typescript-eslint/no-unused-vars": "warn",
+ "@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-var-requires":"off",
"react/no-unescaped-entities": "warn",
"react/prop-types": "off",
diff --git a/src/@types/Components.ts b/src/@types/Components.ts
new file mode 100644
index 0000000..3154f2d
--- /dev/null
+++ b/src/@types/Components.ts
@@ -0,0 +1,9 @@
+export type DropdownBaseProps = {
+ children: React.ReactNode
+}
+
+export type DropdownItemProps = {
+ type?: 'select' | 'multi-select',
+ selected?: boolean,
+ onChange?: React.ReactEventHandler
+} & DropdownBaseProps
\ No newline at end of file
diff --git a/src/components/Selectors.tsx b/src/components/Selectors.tsx
index cab6afe..421aec1 100644
--- a/src/components/Selectors.tsx
+++ b/src/components/Selectors.tsx
@@ -1,4 +1,6 @@
-import React, { useState } from "react";
+import React, { Children, useRef, useState } from "react";
+import ClickDetector from "../util/ClickDetector";
+import { DropdownBaseProps, DropdownItemProps } from "../@types/Components";
export const FileSelector = ({ cb }: { cb: (file: File) => void }) => {
@@ -35,32 +37,82 @@ export const FileSelector = ({ cb }: { cb: (file: File) => void }) => {
;
};
-type DropdownProps = {
- name?: string,
- multi?: boolean,
- selection?: [],
- children: React.ReactNode
-}
-
-export const DropdownMenu = (props: DropdownProps) => {
-
- return
-
-
-
-
- {props.children}
-
-
;
-
-};
-
export const ToggleSwitch = ({ value, onChange, ref, children }:
{ value: boolean, ref?: React.RefObject, onChange?: React.ChangeEventHandler, children: string }) => {
return
- {children}:
+ {children}
;
-};
\ No newline at end of file
+};
+
+export const VerticalToggleSwitch = ({ value, onChange, ref, children }:
+ { value: boolean, ref?: React.RefObject, onChange?: React.ChangeEventHandler, children: string }) => {
+ return
+ {children}
+
+
+
+
;
+};
+
+const DropdownHeader = ({children}: DropdownBaseProps) => {
+ return
+ {children}
+ ;
+};
+
+const DropdownItem = ({ children, type, selected, onChange }: DropdownItemProps) => {
+ if (type === 'multi-select')
+ return
+ {children as string}
+ ;
+ return
+ {children}
+
;
+};
+
+const DropdownItemList = ({ children }: DropdownBaseProps) => {
+ return
+ {children}
+
;
+};
+
+type DropdownProps = {
+ name?: string,
+ multi?: boolean,
+ selection?: [],
+ children: React.ReactNode[]
+}
+
+const DropdownComp = ({children, ...props}: DropdownProps) => {
+
+ console.log(props);
+ console.log(children);
+
+ if (!children)
+ throw new Error('Missing children');
+
+ if (!children.some(element => element && (element as React.ReactElement).type === DropdownHeader))
+ throw new Error('Missing a header');
+
+ const detailsRef = useRef(null);
+
+ return {
+ if(detailsRef.current) detailsRef.current.open = false;
+ }}>
+
+ {children}
+
+ ;
+
+};
+
+const Dropdown = Object.assign(DropdownComp, {
+ Header: DropdownHeader,
+ ItemList: DropdownItemList,
+ Item: DropdownItem
+});
+
+export { Dropdown };
\ No newline at end of file
diff --git a/src/pages/admin/Users.tsx b/src/pages/admin/Users.tsx
index 825f2b1..89ce705 100644
--- a/src/pages/admin/Users.tsx
+++ b/src/pages/admin/Users.tsx
@@ -7,7 +7,7 @@ import { Table, TableListEntry } from "../../components/Table";
import { BackButton, PageButtons } from "../../components/PageControls";
import { Permissions } from "../../views/PermissionsView";
import { Application as App, Permissions as Perms, User as APIUser, Role } from "../../@types/ApiStructures";
-import { DropdownMenu, ToggleSwitch } from "../../components/Selectors";
+import { Dropdown, ToggleSwitch } from "../../components/Selectors";
const ApplicationList = ({ apps }: { apps: App[] }) => {
@@ -38,16 +38,39 @@ const Application = ({ app }: { app: App }) => {
;
};
+const RoleComp = ({ role }: {role: Role}) => {
+ return
+ {role.name}
+
;
+};
+
const Roles = ({ userRoles, roles }: { userRoles: Role[], roles: Role[] }) => {
- console.log(roles);
- return
- {roles.map(role => {
- return
-
- r.id === role.id))} type='checkbox' />
-
;
- })}
- ;
+ console.log(roles, userRoles);
+ const roleSelected = (role: Role, selected: boolean) => {
+ console.log(role, selected);
+ };
+ return
+
+
+ {userRoles.map(role => )}
+
+
+
+
+ {roles.map(role => r.id === role.id)}
+ onChange={(event) => {
+ const elem = event.target as HTMLInputElement;
+ roleSelected(role, elem.checked);
+ }}
+ >
+ {role.name}
+ )}
+
+
+
+ ;
};
const User = ({ user, roles }: { user: APIUser, roles: Role[] }) => {
@@ -99,10 +122,9 @@ const User = ({ user, roles }: { user: APIUser, roles: Role[] }) => {
-
- */}