001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.rest.widget;
018
019import static org.apache.juneau.bean.html5.HtmlBuilder.*;
020import static org.apache.juneau.commons.utils.CollectionUtils.*;
021
022import java.util.*;
023
024import org.apache.juneau.*;
025import org.apache.juneau.bean.html5.*;
026
027/**
028 * Simple template for adding tooltips to HTML5 bean constructs, typically in menu item widgets.
029 *
030 * <p>
031 * Tooltips depend on the existence of the <c>tooltip</c> and <c>tooltiptext</c> styles that should be present in the stylesheet for the document.
032 *
033 * <h5 class='section'>See Also:</h5><ul>
034 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/HtmlPredefinedWidgets">Predefined Widgets</a>
035 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/HtmlWidgets">Widgets</a>
036 * </ul>
037 */
038public class Tooltip {
039
040   private final HtmlText display;
041   private final List<Object> content;
042
043   /**
044    * Constructor.
045    *
046    * @param display The normal display text. <br>
047    *    This is what gets rendered normally. <br>
048    *    The format is raw HTML and can contain markup.
049    * @param content The hover contents. <br>
050    *    Typically a list of strings, but can also include any HTML5 beans as well.
051    */
052   public Tooltip(String display, Object...content) {
053      this.display = new HtmlText(display);
054      this.content = u(l(content));
055   }
056
057   /**
058    * The swap method.
059    *
060    * <p>
061    * Converts this bean into a div tag with contents.
062    *
063    * @param session The bean session.
064    * @return The swapped contents of this bean.
065    */
066   public Div swap(BeanSession session) {
067      return div(small(display), span()._class("tooltiptext").children(content))._class("tooltip");
068   }
069}