Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. import React from 'react';
  2. import { render, Artboard, Text, View, StyleSheet } from 'react-sketchapp';
  3.  
  4. const layout = {
  5. width: 375,
  6. height: 667,
  7. cols: 3,
  8. margin: 100
  9. }
  10.  
  11. const getArtboardStyle = i => {
  12. let { width, height, cols, margin } = layout;
  13. let x = i % cols;
  14. let y = (i - x) / cols;
  15. // Top and left are switched for some reason.
  16. let top = x * (width + margin) + margin;
  17. let left = y * (height + margin) + margin;
  18. let style = {
  19. left,
  20. top,
  21. width,
  22. height,
  23. position: 'fixed',
  24. backgroundColor: '#fff'
  25. }
  26. console.log(style)
  27. return style
  28. }
  29.  
  30. const getParentStyle = count => {
  31. let { width, height, cols, margin } = layout;
  32. let rows = (count - (count % cols)) / cols + 1;
  33. console.log(`${rows} rows, ${cols} cols`)
  34. let totalHeight = rows * (height + margin) + margin;
  35. let totalWidth = cols * (width + margin) + margin;
  36. let style = {
  37. top: 0,
  38. left: 0,
  39. width: totalWidth,
  40. height: totalHeight,
  41. backgroundColor: '#eee'
  42. }
  43. return style
  44. }
  45.  
  46. export default (context) => {
  47. let content = [
  48. <View style={{width: 100, height: 100, backgroundColor: 'green'}}>foo</View>,
  49. <View style={{width: 100, height: 100, backgroundColor: 'green'}}>bar</View>,
  50. <View style={{width: 100, height: 100, backgroundColor: 'green'}}>baz</View>,
  51. <View style={{width: 100, height: 100, backgroundColor: 'green'}}>qux</View>
  52. ]
  53.  
  54. let x = <Artboard name="root" style={getParentStyle(content.length)}>
  55. {content.map((item, i) => <Artboard style={getArtboardStyle(i)} children={item} />)}
  56. </Artboard>
  57. render(x, context.document.currentPage())
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement