Skip to content

Commit

Permalink
refactor: Menu, DatePicker & Textarea improvements (#58)
Browse files Browse the repository at this point in the history
closes #55
closes #57
  • Loading branch information
joduplessis authored Feb 18, 2024
1 parent 35a07c2 commit 7778dea
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 46 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fold-dev",
"title": "Fold",
"version": "0.2.3",
"version": "0.3.0",
"description": "The UI library for product teams.",
"workspaces": {
"packages": [
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@fold-dev/core",
"title": "Fold",
"version": "0.2.3",
"version": "0.3.0",
"description": "The UI library for product teams.",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down
13 changes: 2 additions & 11 deletions packages/core/src/date-time/date-time.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--f-time-picker-color-hover: var(--f-color-text-weak);
--f-time-picker-color-active: var(--f-color-accent);
--f-time-picker-padding: var(--f-space-2) var(--f-space-5);
--f-time-picker-ampm-padding: var(--f-space-3);
}

.f-time-picker {
Expand Down Expand Up @@ -35,7 +36,7 @@
}

.f-time-picker__ampm {
padding: 0 var(--f-space-3);
padding: var(--f-time-picker-ampm-padding);
}

/* date cell */
Expand Down Expand Up @@ -264,17 +265,7 @@

/* scrolling date picker */

:root {
--f-date-scrolling-picker-title-padding: 0.25rem 0;
}

.f-scrolling-date-picker {
position: relative;
overflow-y: auto;
}

.f-scrolling-date-picker__title {
font-weight: 600;
display: inline-block;
padding: var(--f-date-scrolling-picker-title-padding);
}
12 changes: 10 additions & 2 deletions packages/core/src/date-time/date-time.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Popover,
ScrollingDatePicker,
Stack,
Text,
TimePicker,
useScrollingDatePicker,
useVisibility,
Expand Down Expand Up @@ -373,10 +374,17 @@ export const ScrollingPicker = () => {
<Button onClick={handleTodayClick}>Go to Today</Button>
<ScrollingDatePicker
ref={ref}
defaultDate={new Date()}
defaultDate={today}
selection={selection}
onChange={handleSelection}
monthTitle={(date: Date) => '' + `${monthNames[date.getMonth()]} / ${date.getFullYear()}`}
monthTitle={(date: Date) => (
<Text
p="1rem"
as="span"
width="100%">
{monthNames[date.getMonth()]} / {date.getFullYear()}
</Text>
)}
/>
</DateRangeProvider>
</View>
Expand Down
11 changes: 3 additions & 8 deletions packages/core/src/date-time/date-time.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {
ReactElement,
createContext,
forwardRef,
useContext,
Expand Down Expand Up @@ -941,7 +942,7 @@ export type ScrollingDatePickerProps = {
weekdaysProps?: WeekdaysProps
monthProps?: Omit<MonthProps, 'date'>
monthNames?: string[]
monthTitle: (date: Date) => string
monthTitle: (date: Date) => ReactElement
} & Omit<CoreViewProps, 'onChange' | 'disabled'>

export const useScrollingDatePicker = () => {
Expand Down Expand Up @@ -1033,13 +1034,7 @@ export const ScrollingDatePicker = forwardRef((props: ScrollingDatePickerProps,
key={uuid}
className="f-col"
style={{ height, width: '100%' }}>
<Text
as="span"
className="f-scrolling-date-picker__title"
size={size}
width="100%">
{monthTitle(month)}
</Text>
{monthTitle(month)}
<Month
width="100%"
flex={1}
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/input/input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
Popover,
Stack,
Text,
Textarea,
useVisibility,
View,
} from '@fold-dev/core'
Expand Down Expand Up @@ -338,6 +339,20 @@ export const Control = () => {
onChange={(e) => setText(e.target.value)}
/>
</InputControl>

<InputControl>
<InputPrefix>
<IconLib icon="circle" />
</InputPrefix>
<Textarea
autoAdjust
value={text}
maxHeight={300}
className="f-scrollbar"
placeholder="Write message..."
onChange={(e) => setText(e.target.value)}
/>
</InputControl>
</View>
)
}
Expand Down
20 changes: 3 additions & 17 deletions packages/core/src/menu/menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -182,29 +182,14 @@
overflow: hidden;
display: block;
border-top: 0.1rem solid var(--f-menu-divider-color);
margin-top: var(--f-menu-divider-spacing);
margin-bottom: var(--f-menu-divider-spacing);
}

.f-menu-divider > hr {
display: none;
}

/* spacing using sibling selectors */

.f-menu:not(.is-menubar) .f-menu-divider + .f-menu-optiongroup,
.f-menu:not(.is-menubar) .f-menu-divider + .f-menu-heading,
.f-menu:not(.is-menubar) .f-menu-divider + .f-menu-item,
.f-menu:not(.is-menubar) .f-menu-divider + .f-menu-section {
margin-top: var(--f-menu-divider-spacing);
}

.f-menu:not(.is-menubar) .f-menu-optiongroup + .f-menu-divider,
.f-menu:not(.is-menubar) .f-menu-item + .f-menu-divider,
.f-menu:not(.is-menubar) .f-menu-heading + .f-menu-divider
.f-menu:not(.is-menubar) .f-menu-section + .f-menu-divider {
margin-top: var(--f-menu-divider-spacing);
margin-bottom: var(--f-menu-divider-spacing);
}

/* ************************************************************** */
/* ************************************************************** */
/* ************************************************************** */
Expand All @@ -227,6 +212,7 @@

.f-menu-heading {
flex-shrink: 0;
display: inline-block;
}

.f-menu-heading .f-menu-heading__heading {
Expand Down
23 changes: 23 additions & 0 deletions packages/core/src/textarea/textarea.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,26 @@
outline-offset: 1px;
transition: outline 100ms;
}

/*
Please see the <Input /> component.
This adds the ability wrap textarea with <InputControl />.
It would be better to inherit directly there - but this is more explicit.
*/

.f-input-control .f-textarea {
position: relative;
color: inherit;
background-color: transparent !important;
flex: 1;
height: fit-content;
border: 0;
border-color: none;
border-radius: 0;
font-weight: inherit;
font-family: inherit;
box-shadow: none;
transition: none;
outline: none !important;
}

27 changes: 26 additions & 1 deletion packages/core/src/textarea/textarea.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Textarea, View } from '@fold-dev/core'
import { IconLib, InputControl, InputPrefix, Textarea, View } from '@fold-dev/core'
import React, { useState } from 'react'

export default {
Expand Down Expand Up @@ -132,3 +132,28 @@ export const Sizes = () => {
</View>
)
}

// --

/**
* The `InputControl` component can also be used to create a `Textarea` with a prefix or suffix.
*/
export const WithInputControl = () => {
const [text, setText] = useState('')

return (
<InputControl>
<InputPrefix>
<IconLib icon="circle" />
</InputPrefix>
<Textarea
autoAdjust
value={text}
maxHeight={300}
className="f-scrollbar"
placeholder="Write message..."
onChange={(e) => setText(e.target.value)}
/>
</InputControl>
)
}
2 changes: 1 addition & 1 deletion packages/design/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@fold-dev/design",
"title": "Design Tokens",
"version": "0.2.3",
"version": "0.3.0",
"description": "The UI library for product teams.",
"main": "",
"module": "",
Expand Down

0 comments on commit 7778dea

Please sign in to comment.