This folder contains all code examples, that Handsontable uses for myriad reasons, such as documentation, blog, etc. Each code example is a separate project that uses Handsontable to present certain features.
Code examples are structured by Handsontable version. Inside the version directory, examples are grouped by category, which can be anything. The most important category is "docs", which is used in the Handsontable documentation website.
To see a deployed code example you can visit its URL. See Live on production section to learn about the URL structure.
To play around with the actual code for a specific code example you can open it on CodeSandbox. See Preview on CodeSandbox section to learn more.
To run arbitrary code example locally on your machine see How to run the arbitrary code example section.
- Folder structure
- Live on production
- Preview on CodeSandbox
- Creating new examples
- Deployment
- Editing existing examples
- Development
- Testing
Within the /examples
directory, there are all the code examples created for specific Handsontable version and the templates
folder, which contains base projects for creating new code examples. A path to the example follow the undermentioned convention:
/examples/<version_number>/<category>/<framework>/<example_path>
<version_number>
- the destributed version of the Handsontable and Handsontable's wrapper ornext
- the value provided to the NPM scripts as the last argument.<category>
- category of the code examples. The main category isdocs
which means: code examples from the documentation.<framework>
- any supported framework's name (react, angular, vue, js).<example_path>
- path to the specific code example. A folder name of the code example will identify that code example - it will be used as a URL further. The folder name of the code example should be the same across all the frameworks.
An example path to the code example: examples/8.1.0/docs/angular/custom-id
It's worth noting, that the examples
directory is defined as a npm workspace
, as well as each of the <framework>
directories within it. This allows installing shared dependencies for all the framework-specific examples.
All code examples are available online. The base URL for the code examples is https://examples.handsontable.com/handsontable/ and after the slash comes the path to the built project.
URL to the specific project follow the undermentioned convention:
<version_number>/<category>/<framework>/<example_path>
An example URL to the live example: https://examples.handsontable.com/handsontable/8.1.0/docs/js/settings
For more details see the Folder structure section.
To preview the arbitary code example on CodeSandbox you must get the link to the project folder in the Gihub repo. You will find all code examples in our repo https://github.com/handsontable/handsontable/tree/develop/examples.
For example: if the URL to the project is: https://github.com/handsontable/handsontable/tree/develop/examples/next/docs/js/basic-example you can preview that project on CodeSandbox by adding the "box" word right after the "github" and before the ".com". The URL to the sandboxed project would be https://githubbox.com/handsontable/handsontable/tree/develop/examples/next/docs/js/basic-example .
Read the Templates Guideline for the detailed information about new code examples creation.
After new code examples are merged into master branch and the new version of the Handsontable has been released to the NPM, you can safely deploy new examples.
In Github Actions run a manual workflow with the <version_number>
input for the Handsontable version. The new folder will be created: /examples/<version_number>
. Within that folder, new code examples will be created with Handsontable version fixed to the <version_number>
.
The new code snippets will be deployed to the Github Pages and will be available under URL mentioned in the "Live on production" section in the Code Examples README.
Sometimes you want to edit existing code examples that is live in the /examples/<version_number>
directory.
- Edit code examples within the
/examples/<version_number>
directory. - Commit and push the code examples to the repo.
- In Github Actions run a manual workflow with the
<version_number>
input of the Handsontable and Handsontable's wrapper version. - The code examples will be deployed to the Github Pages and will be available under the same URL as they already were.
To see code examples in action run these commands:
npm run examples:install <version_number>
- will install the dependencies of all the examples matching the<version_number>
, utilizing theexamples
' internal workspace logic.npm run examples:build <version_number>
- will build each code example in the/examples/<version_number>
directory then copy each example's production output to the/examples/tmp/<version_number>
. The path to the code example in the/examples/tmp
follows the Folder structure convention.npm run examples:start
- it will start thehttp-server
right in the/examples/tmp
on PORT8080
. So the URL to the specific code example would behttp://localhost:8080/8.1.0/docs/angular/custom-context-menu/
. The URL follows the same convention as mentioned in the Live on production section.
Important: As the next
directory of the examples uses the local builds of handsontable
and the wrappers, for the next
build process to work, all the root-level packages need to be built (for example, bu running npm run all build
) before running the examples build script.
To launch only one code example, go to the project directory, run npm install
and npm run start
. This will instal all the project dependencies and start a development server. After this command is called visit http://localhost:8080.
Each code example has its own test specs, which lives in the spec
directory.
Templates have one failing test, which has been added to force developers to write passing tests for the next code examples.
Each code example has its own test suites which you can run using a development server:
- Run the
npm run start
command. - After the app is launched on a server, run the
npm run test
command which will launch tests specified to this code example.
- Code examples must exist in the
examples/<version_number>
directory and be built using the commandnpm run examples:build <version_number>
. npm run examples:test <version_number>
. This command will runnpm run test
for each code example (to know what thenpm run test
command does check out the section above).