Giter Site home page Giter Site logo

vaadin / cookbook Goto Github PK

View Code? Open in Web Editor NEW
20.0 30.0 39.0 5.1 MB

Copy & paste recipes for Vaadin

Home Page: https://cookbook.vaadin.com/

License: Apache License 2.0

HTML 0.63% TypeScript 8.90% JavaScript 1.91% Java 85.81% Dockerfile 0.20% CSS 2.55%

cookbook's Introduction

Vaadin Cookbook

A collection of solutions to common use cases you run into when developing business web applications.

All solutions should be of the type "The user of my app wants to ..." and focus on functionality.

Solutions are implemented using Java, TS or a mix that is appropriate. The focus is on the solution, not how it is implemented.

The project is deployed at https://cookbook.vaadin.com/

General guidelines for recipes

Try to keep recipes short and show one thing. The focus is on the functionality which can be copy pasted to another project.

Try to keep recipes in one file. Use a few files if really needed. Use common sense.

Recipes cannot be wrong if they work but all recipes can be improved. It is better to improve an existing recipe than create another one which is almost the same.

Recipes are written in TS or Java. The Java version should be compatible with Vaadin 14. The TS version requires Vaadin 16+.

Contributing a Java UI based recipe

  1. If you want to avoid problems with other people contributing the same idea at the same time, create or find an issue describing the intent (one sentence is typically enough) and accept the issue
  2. Fork and clone the project
  3. Create a Java package for your recipe
mkdir src/main/java/com/vaadin/recipes/recipe/recipenamegoeshere/
  1. Create a Java file in the folder with the following
import com.vaadin.flow.router.Route;
import com.vaadin.recipes.recipe.Metadata;
import com.vaadin.recipes.recipe.Recipe;

@Route("recipe-name-goes-here")
@Metadata(
  howdoI = "Short (< 50) character explanation",
  description = "150-160 character description that is shown on the listing page and Google search results."
)
public class RecipeNameGoesHere extends Recipe {
}
  1. Code the recipe and test it. Start the project using mvn and you find your recipe at http://localhost:8080/recipe-name-goes-here

  2. If you created multiple files (Java or CSS), refer to them using the sourceFiles attribute of @Metadata

  3. If your recipe needs push, add tag={Tag.PUSH} to @Metadata. Add any other suitable tags also.

  4. Commit and create a PR

  5. Wait for 1-2 days for somebody to react to the PR

  6. Fix any potential comments

  7. ๐ŸŽ‰

Contributing a TS based recipe

  1. If you want to avoid problems with other people contributing the same idea at the same time, create or find an issue describing the intent (one sentence is typically enough) and accept the issue
  2. Fork and clone the project
  3. Create a TS folder for your recipe
mkdir frontend/recipe/recipe-name-goes-here/
  1. Create a TS file in the folder with the following
import { html } from "lit";
import { customElement } from "lit/decorators.js";
import { Recipe, recipeInfo } from "../recipe";

@recipeInfo({
  url: "recipe-name-goes-here",
  howDoI: "Short (< 50) character explanation",
  description: "150-160 character description that is shown on the listing page and Google search results."
})
@customElement("recipe-name-goes-here")
export class RecipeNameGoesHere extends Recipe {
  render() {
    return html`
      <div>Template goes here</div>
      `;
  }
}
  1. Code the recipe and test it. Start the project using mvn and you find your recipe at http://localhost:8080/recipe-name-goes-here

  2. If you created multiple files (TS or CSS), refer to them using the sourceFiles attribute of @recipeInfo

  3. Add any suitable tags to the tags part of @recipeInfo

  4. Commit and create a PR

  5. Wait for 1-2 days for somebody to react to the PR

  6. Fix any potential comments

  7. ๐ŸŽ‰

Running the project

In most cases you can run the project using

mvn

or by launching the Application class from an IDE.

If you want to run the project on a different port than 8080, you can do

PORT=9090 mvn

cookbook's People

Contributors

alvarezguille avatar anezthes avatar artur- avatar benwilsoni avatar dbenninger avatar emarc avatar enver-haase avatar haijian-vaadin avatar hawksk avatar javier-godoy avatar jcgueriaud1 avatar johannest avatar jouni avatar lbruun avatar legioth avatar manolo avatar marcushellberg avatar mrgreywater avatar mstahv avatar olafj avatar ollitietavainenvaadin avatar paulroemer avatar peppe avatar samie avatar sebastiankuehnau avatar sissbruecker avatar stefanuebe avatar tarekoraby avatar tatulund avatar tomivirkki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cookbook's Issues

Rename Java tag Flow, TypeScript Fusion

Rename the Java tag Flowand TypeScript to Fusion where it makes sense. This way they will use the same terminology as our website, docs, forum, and discord.

Example code does not work when copy pasted into another project

Take https://cookbook.vaadin.com/grid-csv-export

It uses

import org.vaadin.artur.exampledata.DataType;
import org.vaadin.artur.exampledata.ExampleDataGenerator;

which you do not know how to include in your project

It has

import com.vaadin.recipes.recipe.Metadata;
@Metadata(howdoI = "Export grid data as CSV")

which is only relevant for the cookbook app itself

It has

import com.vaadin.recipes.recipe.Recipe;
public class GridCsvExport extends Recipe {

which is only relevant for the cookbook app itself

It should be possible to grab
https://start.vaadin.com?dl

and paste the code as a new file and then get it to work by not reading anything else than the code

Remove app-specific code from preview

The recipes include few pieces of code that are specific to the cookbook app:

  • package name (e.g. package com.vaadin.recipes.recipe.camera;)
  • com.vaadin.recipes.recipe.Metadata
  • com.vaadin.recipes.recipe.Recipe

For better UX, remove those from the preview of the recipe.

The user wants forms divided into tabs

  • View has static section which contains Save/Cancel actions.
  • View content is divided into tabs.
  • The entries on one tab may have effect on other tabs.
  • User needs to be able to tell if there are validation errors on a tab.
  • Validation is run across all tabs then any entries are done.

image

How do I change label color dependending on value

What will this enable for the user?
As a user of the application, I want to see color coded text elements (so that I can identify their value quickly without even reading the text, especially when there are several simultaneous instances of the element, such as in a grid)

Recipe tags (optional):
styling, colors

Related tags (optional):

How do I print a Grid

What will this enable for the user?
As a user of the application, I want to be able to print a Grid, or generate a printable PDF document out of the Grid, that has more than 1 viewport's height worth of content (but still a reasonable size, less than 20 pages for the sake of the example). One possible way this can be implemented by having a custom "print" URL/route which shows a paged version of the Grid and the requested page can be added as an additional route parameter. In other words, /print/0 has the first page, /print/1 has the second page, and so on. These routes can then be accessed sequentially with a headless browser to generate pages of the full document.

Recipe tags (optional):
printing, grid

How do I copy text to the clipboard

What will this enable for the user?
As a user of the application, I want to click a "copy to clipboard" -button, so that I can paste the relevant content into another application.

Recipe tags (optional):
copy, paste, clipboard

Related tags (optional):

How do I lazily initialize components

What will this enable for the user?
As a user of the application, I want to add a placeholder for a component that requires a long backend task. A chart that requires a long SQL query ...

Recipe tags (optional):

Related tags (optional):

How do I browse a hierarchical file system, a file tree?

What will this enable for the user?
As a user of the application, I want to browse a file system (so that I can view or download files from there)

This is a placeholder to remind me I should incorporate Amahdy's old blog post solution here.

Recipe tags (optional):
TreeGrid

Related tags (optional):
Tree

Lazy Component View recipe needs @Push, otherwise cannot work

Took me a few hours to understand what was happening.
Spinner layout spins forever and cannot reveal the correctly loaded component.
Please document @Push needs to be enabled on topmost Router Layout.

Suggest also a few cleanups, as e.g. the whole of the overlay can simply be removed, and no public methods need to exist like 'isLoading' or that method with a boolean parameter that's always 'true' (setLoaded). Most stuff can be private to LazyContainer and still be accessed by its inner classes (no getComponent() method needed for example, just access the private final field).

Cheers,
Enver

[bug] global css styles missing on navigating

Opening the cookbook example, all looks good (the headings are readable):

image

Clicking on the first cookbook entry, the entry looks like this (hard to read):

image

Going back with the browser back bar or the "Back to Cookbook" action (a lot of headings hard to read):

image

Browser: Firefox 96.0b3

How do I copy Grid or Table content to the clipboard

What will this enable for the user?
As a user of the application, I want to easily copy&paste the content of a Grid/Table to the clipboard, so that I can paste into another application.

Recipe tags (optional):
copy, paste, clipboard, grid, table

Related tags (optional):
csv

How do I Allow MenuBar overflow button

What will this enable for the user?
As a user of the application, I want to use a MenuBar in a HorizontalLayout so that when I resize the browser width the buttons that do not fit hide inside the overflow button.

Recipe tags (optional):
layout

Example "Add template renderer in grid and handle events" did not work as expected

Hi,

we have problems with your sample.

Steps to reproduce:

  1. Click on the first "click me" after start
  2. "click me" Button will be disabled
  3. Scroll down and you well see more disabled "click me" Buttons you never clicked

Is there any workaround for this because we must use this technique in our application but are showstopped because of this

Stefan

How do I create different types of notifications

What will this enable for the user?
As a user of the application, I want to see different types of notifications which's behaviour is based on severity.

Common use case is to have four notification types: Generic, Success, Warning and Error.
Each type should have set of rules based that define the behaviour.

Parameters pre-defined by each type are

  • Position
  • Theme variant (visual style)
  • Closing behaviour
    • Timeout (success and non-critical notifications)
    • Close button (warnings and errors that require user acknowledge)
    • Action buttons (warnings and errors that require user's decision)
    • Non-closable (i.e. background process)

Screenshot from customer case:
image

Recipe tags (optional):
Notifications

Related tags (optional):

How do I print a subset of components

What will this enable for the user?
As a user of the application, I want to specify the subset of components that would be printed

Recipe tags: Flow

How do I create a TabSheet

What will this enable for the user?
As a user of the application, I want selecting a Tab to change the content underneath

Recipe tags (optional):
Spicy, Lactose-Free

Related tags (optional):

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.