-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: view * v0.9.23 * revert new version * decouple props and styling * pass padding as prop * WIP * add style props to view * Add some colors * rm unused import * add provider, spread args * create border and color types * rm unused imports * address feedback * address feedback * 0.9.23 * revert * v0.9.23 --------- Co-authored-by: Mikyo King <[email protected]>
- Loading branch information
1 parent
1fa66b7
commit 1028284
Showing
9 changed files
with
354 additions
and
30 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
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,80 @@ | ||
import React, { JSXElementConstructor, ReactNode, forwardRef } from 'react'; | ||
import { css } from '@emotion/react'; | ||
import { | ||
BackgroundColorValue, | ||
BorderColorValue, | ||
BorderRadiusValue, | ||
DOMRef, | ||
DimensionValue, | ||
} from '../types'; | ||
import { useDOMRef } from '../utils'; | ||
import { dimensionValue } from '../utils/styleProps'; | ||
|
||
export interface ViewProps { | ||
/** | ||
* The children to be displayed in the View. | ||
*/ | ||
children?: ReactNode; | ||
/** | ||
* The element to render as the node. | ||
* @default 'div' | ||
*/ | ||
elementType?: string | JSXElementConstructor<any>; | ||
padding?: Extract< | ||
DimensionValue, | ||
'static-size-50' | 'static-size-100' | 'static-size-200' | ||
>; | ||
borderRadius?: BorderRadiusValue; | ||
borderColor?: BorderColorValue; | ||
backgroundColor?: BackgroundColorValue; | ||
width?: DimensionValue; | ||
height?: DimensionValue; | ||
id?: string; | ||
} | ||
|
||
function View(props: ViewProps, ref: DOMRef) { | ||
const { | ||
children, | ||
elementType: ElementType = 'div', | ||
padding, | ||
borderRadius, | ||
borderColor, | ||
backgroundColor, | ||
width, | ||
height, | ||
id, | ||
} = props; | ||
const domRef = useDOMRef(ref); | ||
return ( | ||
<ElementType | ||
ref={domRef} | ||
css={css` | ||
overflow: hidden; | ||
padding: ${padding != null ? dimensionValue(padding) : 0}; | ||
border: 1px solid | ||
${borderColor != null | ||
? `var(--ac-global-border-color-${borderColor})` | ||
: 'transparent'}; | ||
background-color: ${backgroundColor != null | ||
? `var(--ac-global-background-color-${backgroundColor})` | ||
: 'transparent'}; | ||
border-radius: ${borderRadius != null | ||
? `var(--ac-global-rounding-${borderRadius})` | ||
: 0}; | ||
width: ${width != null ? dimensionValue(width) : 'auto'}; | ||
height: ${height != null ? dimensionValue(height) : 'auto'}; | ||
`} | ||
className="ac-view" | ||
id={id} | ||
> | ||
{children} | ||
</ElementType> | ||
); | ||
} | ||
|
||
/** | ||
* View is a general purpose container with no specific semantics | ||
* that can be used for custom styling purposes, similar to a div. | ||
*/ | ||
const _View = forwardRef(View); | ||
export { _View as View }; |
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 +1,2 @@ | ||
export * from './Content'; | ||
export * from './View'; |
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.