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.bean.html5;
018
019import org.apache.juneau.marshall.*;
020
021/**
022 * DTO for an HTML <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#the-optgroup-element">&lt;optgroup&gt;</a>
023 * element.
024 *
025 * <p>
026 * The optgroup element represents a group of option elements within a select element. It provides
027 * a way to organize related options into logical groups, making it easier for users to find and
028 * select the desired option. The label attribute provides the group heading.
029 *
030 * <h5 class='section'>Examples:</h5>
031 * <p class='bcode w800'>
032 *    <jk>import static</jk> org.apache.juneau.bean.html5.HtmlBuilder.*;
033 *
034 *    <jc>// Simple option group</jc>
035 *    Optgroup <jv>optgroup1</jv> = <jsm>optgroup</jsm>(<js>"Fruits"</js>,
036 *       <jsm>option</jsm>(<js>"apple"</js>, <js>"Apple"</js>),
037 *       <jsm>option</jsm>(<js>"banana"</js>, <js>"Banana"</js>),
038 *       <jsm>option</jsm>(<js>"orange"</js>, <js>"Orange"</js>)
039 *    );
040 *
041 *    <jc>// Disabled option group</jc>
042 *    Optgroup <jv>optgroup2</jv> = <jsm>optgroup</jsm>(<js>"Vegetables"</js>,
043 *       <jsm>option</jsm>(<js>"carrot"</js>, <js>"Carrot"</js>),
044 *       <jsm>option</jsm>(<js>"broccoli"</js>, <js>"Broccoli"</js>)
045 *    ).disabled(<jk>true</jk>);
046 *
047 *    <jc>// Multiple option groups in a select</jc>
048 *    Select <jv>select1</jv> = <jsm>select</jsm>(<js>"food"</js>,
049 *       <jsm>optgroup</jsm>(<js>"Fruits"</js>,
050 *          <jsm>option</jsm>(<js>"apple"</js>, <js>"Apple"</js>),
051 *          <jsm>option</jsm>(<js>"banana"</js>, <js>"Banana"</js>)
052 *       ),
053 *       <jsm>optgroup</jsm>(<js>"Vegetables"</js>,
054 *          <jsm>option</jsm>(<js>"carrot"</js>, <js>"Carrot"</js>),
055 *          <jsm>option</jsm>(<js>"broccoli"</js>, <js>"Broccoli"</js>)
056 *       )
057 *    );
058 * </p>
059 *
060 * <p>
061 * The following convenience methods are provided for constructing instances of this bean:
062 * <ul class='javatree'>
063 *    <li class='jc'>{@link HtmlBuilder}
064 *    <ul class='javatree'>
065 *       <li class='jm'>{@link HtmlBuilder#optgroup() optgroup()}
066 *       <li class='jm'>{@link HtmlBuilder#optgroup(Object...) optgroup(Object...)}
067 *    </ul>
068 * </ul>
069 * </p>
070 *
071 * <h5 class='section'>See Also:</h5><ul>
072 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a>
073 * </ul>
074 */
075@Marshalled(typeName = "optgroup")
076public class Optgroup extends HtmlElementContainer<Optgroup> {
077
078   /**
079    * Creates an empty {@link Optgroup} element.
080    */
081   public Optgroup() {}
082
083   /**
084    * Creates an {@link Optgroup} element with the specified child nodes.
085    *
086    * @param children The child nodes. Must not be <jk>null</jk>.
087    */
088   public Optgroup(Object...children) {
089      children(children);
090   }
091
092   /**
093    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-optgroup-disabled">disabled</a> attribute.
094    *
095    * <p>
096    * Whether the form control is disabled.
097    *
098    * <p>
099    * This attribute uses deminimized values:
100    * <ul>
101    *    <li><jk>false</jk> - Attribute is not added</li>
102    *    <li><jk>true</jk> - Attribute is added as <js>"disabled"</js></li>
103    *    <li>Other values - Passed through as-is</li>
104    * </ul>
105    *
106    * @param value
107    *    The new value for this attribute.
108    *    Typically a {@link Boolean} or {@link String}.
109    *    Can be <jk>null</jk> to unset the attribute.
110    * @return This object.
111    */
112   public Optgroup disabled(Object value) {
113      attr("disabled", deminimize(value, "disabled"));
114      return this;
115   }
116
117   /**
118    * <a class="doclink" href="https://www.w3.org/TR/html5/forms.html#attr-optgroup-label">label</a> attribute.
119    *
120    * <p>
121    * Specifies the user-visible label for the option group. This label is displayed
122    * in the select element to group related options together.
123    *
124    * <p>
125    * The label should be descriptive and help users understand the grouping of options.
126    *
127    * @param value The user-visible label for the option group. Can be <jk>null</jk> to unset the attribute.
128    * @return This object.
129    */
130   public Optgroup label(String value) {
131      attr("label", value);
132      return this;
133   }
134
135}