UNPKG

react-crossword-v2

Version:

A flexible, responsive, and easy-to-use crossword component for React apps

54 lines (47 loc) 1.41 kB
To make crosswords as easy to create as possible, with the least amount of extraneous and boilerplate typing, the clue/answer format is structured as a set of nested objects: ```javascript static { across: { 1: { clue: 'one plus one', answer: 'TWO', row: 0, col: 0, }, }, down: { 2: { clue: 'three minus two', answer: 'ONE', row: 0, col: 2, }, }, } ``` At the top level, the `across` and `down` properties group together the clues/answers for their respective directions. Each of those objects is a map, keyed by the answer number rather than an array. (This is done so that the creator has control over the numbering/labelling of the clues/answers.) Each item contains a `clue` and `answer` property, as well as `row` and `col` for the starting position. ```jsx import Crossword from '@jaredreisinger/react-crossword'; const data = { across: { 1: { clue: 'one plus one', answer: 'TWO', row: 0, col: 0, }, }, down: { 2: { clue: 'three minus two', answer: 'ONE', row: 0, col: 2, }, }, }; <div style={{ width: '25em', display: 'flex' }}> <Crossword data={data} /> </div>; ``` The `CrosswordProvider` component (automatically used by `Crossword`) calculates the needed grid size from the data itself, so you don't need to pass an overall size to the component.