-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
627 additions
and
224 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,8 @@ const Flex = styled.div<FlexProps>` | |
& ${ButtonDefault} { | ||
align-self: flex-start; | ||
} | ||
& > p { | ||
margin: 0; | ||
} | ||
`; |
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,72 @@ | ||
import { FC, PropsWithChildren } from 'react'; | ||
import * as RadixTabs from '@radix-ui/react-tabs'; | ||
import { styled } from 'styled-components'; | ||
import { transition } from '../helpers/transition'; | ||
|
||
type TabItem = { | ||
label: string; | ||
value: string; | ||
}; | ||
|
||
interface TabsProps { | ||
tabs: TabItem[]; | ||
className?: string; | ||
label: string; | ||
} | ||
|
||
export const Tabs: FC<PropsWithChildren<TabsProps>> = ({ | ||
children, | ||
tabs, | ||
label, | ||
className, | ||
}) => { | ||
return ( | ||
<RadixTabs.Root defaultValue={tabs[0].value} className={className}> | ||
<TabList aria-label={label}> | ||
{tabs.map(tab => ( | ||
<TabButton key={tab.value} value={tab.value}> | ||
{tab.label} | ||
</TabButton> | ||
))} | ||
</TabList> | ||
{children} | ||
</RadixTabs.Root> | ||
); | ||
}; | ||
|
||
interface TabPanelProps { | ||
value: string; | ||
} | ||
|
||
export const TabPanel: FC<PropsWithChildren<TabPanelProps>> = ({ | ||
value, | ||
children, | ||
}) => { | ||
return <RadixTabs.Content value={value}>{children}</RadixTabs.Content>; | ||
}; | ||
|
||
const TabList = styled(RadixTabs.List)` | ||
display: flex; | ||
justify-content: space-evenly; | ||
margin-bottom: ${p => p.theme.margin}rem; | ||
`; | ||
|
||
const TabButton = styled(RadixTabs.Trigger)` | ||
background: none; | ||
border: none; | ||
color: ${p => p.theme.colors.text}; | ||
border-bottom: 1px solid ${p => p.theme.colors.bg2}; | ||
padding: 1rem; | ||
flex: 1; | ||
${transition('background', 'border-bottom')} | ||
cursor: pointer; | ||
&:hover, | ||
&:focus-visible { | ||
outline: none; | ||
background: ${p => p.theme.colors.bg1}; | ||
} | ||
&[data-state='active'] { | ||
border-bottom: 2px solid ${p => p.theme.colors.main}; | ||
} | ||
`; |
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,77 @@ | ||
import { Resource, core, dataBrowser, useStore } from '@tomic/react'; | ||
import { useState, useCallback, Suspense, lazy } from 'react'; | ||
import { FaPlus } from 'react-icons/fa'; | ||
import { randomItem } from '../../helpers/randomItem'; | ||
import { randomString } from '../../helpers/randomString'; | ||
import { stringToSlug } from '../../helpers/stringToSlug'; | ||
import { Button } from '../Button'; | ||
import { Row } from '../Row'; | ||
import { InputWrapper, InputStyled } from '../forms/InputStyles'; | ||
import { tagColours } from './tagColours'; | ||
|
||
const EmojiInput = lazy(() => import('../../chunks/EmojiInput/EmojiInput')); | ||
|
||
interface CreateTagRowProps { | ||
parent: string; | ||
onNewTag: (tag: Resource) => void; | ||
} | ||
|
||
export function CreateTagRow({ parent, onNewTag }: CreateTagRowProps) { | ||
const store = useStore(); | ||
const [tagName, setTagName] = useState<string>(''); | ||
const [emoji, setEmoji] = useState<string | undefined>(); | ||
const [resetKey, setResetKey] = useState<number>(0); | ||
|
||
const createNewTag = useCallback(async () => { | ||
const tag = await store.newResource({ | ||
subject: `${parent}/${randomString()}`, | ||
parent, | ||
isA: dataBrowser.classes.tag, | ||
propVals: { | ||
[core.properties.shortname]: tagName, | ||
[dataBrowser.properties.color]: randomItem(tagColours), | ||
}, | ||
}); | ||
|
||
if (emoji) { | ||
await tag.set(dataBrowser.properties.emoji, emoji, store); | ||
} | ||
|
||
onNewTag(tag); | ||
setTagName(''); | ||
setEmoji(undefined); | ||
setResetKey(prev => prev + 1); | ||
}, [parent, store, tagName, emoji, onNewTag]); | ||
|
||
const handleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => { | ||
setTagName(stringToSlug(e.target.value)); | ||
}, []); | ||
|
||
const handleKeyDown = useCallback( | ||
(e: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (e.key === 'Enter') { | ||
createNewTag(); | ||
} | ||
}, | ||
[createNewTag], | ||
); | ||
|
||
return ( | ||
<Suspense fallback={<div>Loading...</div>}> | ||
<Row> | ||
<InputWrapper> | ||
<EmojiInput onChange={setEmoji} key={resetKey} /> | ||
<InputStyled | ||
placeholder='New tag' | ||
value={tagName} | ||
onChange={handleChange} | ||
onKeyDown={handleKeyDown} | ||
/> | ||
</InputWrapper> | ||
<Button title='Add tag' onClick={createNewTag} disabled={!tagName}> | ||
<FaPlus /> | ||
</Button> | ||
</Row> | ||
</Suspense> | ||
); | ||
} |
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,2 @@ | ||
export * from './Tag'; | ||
export * from './CreateTagRow'; |
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,8 @@ | ||
export const tagColours = [ | ||
'#FFBE0B', | ||
'#FB5607', | ||
'#FF006E', | ||
'#8338EC', | ||
'#3A86FF', | ||
'#5FF56E', | ||
]; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { styled } from 'styled-components'; | ||
|
||
export const LabelText = styled.span` | ||
font-weight: bold; | ||
color: ${p => p.theme.colors.textLight}; | ||
`; |
Oops, something went wrong.