-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
1 parent
0a90e75
commit 999aa66
Showing
9 changed files
with
161 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Artem Zakharchenko | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,45 @@ | ||
{ | ||
"name": "@atomic-layout/emotion", | ||
"description": "Physical representation of layout composition to create declarative, responsive layouts in React.", | ||
"version": "0.11.0", | ||
"license": "MIT", | ||
"scripts": { | ||
"lint": "tslint -c tslint.json 'src/**/*.{ts,tsx}'" | ||
}, | ||
"peerDependencies": { | ||
"react": ">= 16.8", | ||
"@emotion/core": ">= 10.0", | ||
"@emotion/styled": ">= 10.0" | ||
}, | ||
"dependencies": { | ||
"@atomic-layout/core": "^0.11.0" | ||
}, | ||
"files": [ | ||
"lib", | ||
"README.md" | ||
], | ||
"author": { | ||
"name": "Artem Zakharchenko", | ||
"email": "[email protected]" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/kettanaito/atomic-layout/packages/atomic-layout-emotion" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/kettanaito/atomic-layout/issues" | ||
}, | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/atomic-layout" | ||
}, | ||
"keywords": [ | ||
"atomic", | ||
"layout", | ||
"responsive", | ||
"composition", | ||
"css grid", | ||
"react", | ||
"emotion" | ||
] | ||
} |
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,20 @@ | ||
import * as React from 'react' | ||
import styled from '@emotion/styled' | ||
import { BoxProps, applyStyles } from '@atomic-layout/core' | ||
|
||
const Box: React.FC<BoxProps> = styled.div` | ||
display: ${({ flex, inline }) => | ||
flex | ||
? inline | ||
? 'inline-flex' | ||
: 'flex' | ||
: inline | ||
? 'inline-block' | ||
: 'block'}; | ||
&& { | ||
${applyStyles} | ||
} | ||
` | ||
|
||
export default Box |
49 changes: 49 additions & 0 deletions
49
packages/atomic-layout-emotion/src/components/Composition.tsx
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,49 @@ | ||
import * as React from 'react' | ||
import { | ||
AreaComponent, | ||
BoxProps, | ||
CompositionProps, | ||
CompositionRenderProp, | ||
applyStyles, | ||
parseTemplates, | ||
generateComponents, | ||
} from '@atomic-layout/core' | ||
import styled from '@emotion/styled' | ||
import Box from './Box' | ||
import { withPlaceholder } from '../../../atomic-layout/src/utils/withPlaceholder' | ||
|
||
const CompositionWrapper = styled.div<CompositionProps>` | ||
&& { | ||
${applyStyles}; | ||
display: ${({ inline }) => (inline ? 'inline-grid' : 'grid')}; | ||
} | ||
` | ||
|
||
const createAreaComponent = (areaName: string): AreaComponent => ( | ||
props: BoxProps, | ||
) => <Box area={areaName} {...props} /> | ||
|
||
const Composition: React.FC<CompositionProps> = ({ | ||
children, | ||
...restProps | ||
}) => { | ||
const areasList = parseTemplates(restProps) | ||
const Areas = generateComponents( | ||
areasList, | ||
createAreaComponent, | ||
withPlaceholder, | ||
) | ||
const hasAreaComponents = Object.keys(Areas).length > 0 | ||
const childrenType = typeof children | ||
const hasRenderProp = childrenType === 'function' | ||
|
||
return ( | ||
<CompositionWrapper {...restProps}> | ||
{hasAreaComponents && hasRenderProp | ||
? (children as CompositionRenderProp)(Areas) | ||
: children} | ||
</CompositionWrapper> | ||
) | ||
} | ||
|
||
export default Composition |
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,16 @@ | ||
import { Layout } from '@atomic-layout/core' | ||
export default Layout | ||
|
||
/* Components */ | ||
export { default as Box } from './components/Box' | ||
export { default as Composition } from './components/Composition' | ||
|
||
/* Hooks */ | ||
export { | ||
MediaQuery, | ||
useBreakpointChange, | ||
useResponsiveComponent, | ||
useResponsiveProps, | ||
useResponsiveValue, | ||
useViewportChange, | ||
} from '../../atomic-layout/src' |
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,3 @@ | ||
{ | ||
"extends": ["../atomic-layout/tslint.json"] | ||
} |
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