0.3.4 • Published 3 years ago

svelte-crossword v0.3.4

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

svelte-crossword

By Amelia Wattenberger and Russell Goldenberg.

Examples

Example page

Features

  • Generate puzzle from simple JSON format
  • Slottable toolbar that can tap into crossword methods
  • Fully responsive
  • Optimized for mobile with on-screen keyboard
  • Preset style themes with customization
  • Puzzle validation
  • Custom class names for cells and clues

Installation

npm install svelte-crossword

Usage

<script>
  import Crossword from "svelte-crossword";
  const data = [
    {
      "clue": "Black-and-white cookie",
      "answer": "OREO",
      "direction": "down",
      "x": 0,
      "y": 0
    },
    ...
  ]
</script>

<Crossword data="{data}" />

Data format

An array of objects with the following required properties:

propertytypedescription
clueStringClue text
answerStringAnswer text (auto-capitalizes)
directionString"across" or "down"
xNumberstarting x position (column) of clue
yNumberstarting y position (row) of clue
customStringoptional custom class name to apply
[
  {
    "clue": "Clue text",
    "answer": "ANSWER",
    "direction": "across",
    "x": 0,
    "y": 0,
    "custom": "class-name"
  }
]

Note: X and Y coordinates can be zero or one based, it will detect automatically.

Parameters

parameterdefaulttypedescription
datarequiredArraycrossword clue/answer data
theme"classic"Stringpreset theme to use
actions["clear", "reveal", "check"]Arraytoolbar actions
revealDuration1000Numberreveal transition duration in ms
breakpoint720Numberwhen to switch to stacked layout
disableHighlightfalseBooleanturn off puzzle highlight
showCompleteMessagetrueBooleanshow message overlay after completion
showConfettitrueBooleanshow confetti during completion message
showKeyboardfalseBooleanforce on-screen keyboard display (overriding auto-check)
keyboardStyle"outline"Stringkeyboard button style

Bindings

bindingtypedescription
revealedBooleanIf the puzzle is showing all answers or not

Themes and Custom Styles

You can choose a preset theme by passing the prop: <Crossword theme="classic" />

Available themes:

  • classic (default)
  • dark
  • citrus
  • amelia

You can set your own global CSS variables to override theme defaults or roll-your-own. Simply create new a CSS variable prefixed with xd- to override the defaults. A Crossword component has a top-level class of .svelte-crossword.

Properties (with defaults)

.svelte-crossword {
  --xd-font: sans-serif; /* font-family for whole puzzle */
  --xd-primary-highlight-color: #ffcc00; /* color for focused cell */
  --xd-secondary-highlight-color: #ffec99; /* color for other cells in current clue */
  --xd-main-color: #1a1a1a; /* color for text, gridlines, void cells */
  --xd-bg-color: #fff; /* color for puzzle background */
  --xd-accent-color: #efefef; /* color for buttons */
  --xd-scrollbar-color: #cdcdcd; /* color for scrollbar handle */
  --xd-order: row; /* row = clues on left, row-reverse = clues on right  */
}

For more detailed customization, simply do a more targeted CSS selection. For example...

.svelte-crossword .cell text.number {
  font-size: 0.5em;
}

Custom Slots

You can provide more fine-grained control over the toolbar and completion message with custom slots.

Toolbar

<Crossword>
	<div
		class="toolbar"
		slot="toolbar"
		let:onClear
		let:onReveal
		let:onCheck >
		<button on:click="{onClear}">clear puzzle</button>
		<button on:click="{onReveal}">show answers</button>
		<button on:click="{onCheck}">check cells</button>
	</div>
<Crossword>

Completion Message

<Crossword>
	<div slot="complete">
		<h3>OMG, congrats!</h3>
		<img
			alt="celebration"
			src="https://media3.giphy.com/media/QpOZPQQ2wbjOM/giphy.gif" />
	</div>
</Crossword>

Development

cd example
npm run dev

Notes

Approaches

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.3

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago