Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / menu / ColorPicker.js
1 /**
2  * @class Ext.menu.ColorPicker
3  * @extends Ext.menu.Menu
4  * <p>A menu containing a {@link Ext.picker.Color} Component.</p>
5  * <p>Notes:</p><div class="mdetail-params"><ul>
6  * <li>Although not listed here, the <b>constructor</b> for this class
7  * accepts all of the configuration options of <b>{@link Ext.picker.Color}</b>.</li>
8  * <li>If subclassing ColorMenu, any configuration options for the ColorPicker must be
9  * applied to the <tt><b>initialConfig</b></tt> property of the ColorMenu.
10  * Applying {@link Ext.picker.Color ColorPicker} configuration settings to
11  * <b><tt>this</tt></b> will <b>not</b> affect the ColorPicker's configuration.</li>
12  * </ul></div>
13  * {@img Ext.menu.ColorPicker/Ext.menu.ColorPicker.png Ext.menu.ColorPicker component}
14  * __Example Usage__
15      var colorPicker = Ext.create('Ext.menu.ColorPicker', {
16         value: '000000'
17     });
18
19     Ext.create('Ext.menu.Menu', {
20                 width: 100,
21                 height: 90,
22                 floating: false,  // usually you want this set to True (default)
23                 renderTo: Ext.getBody(),  // usually rendered by it's containing component
24                 items: [{
25                     text: 'choose a color',
26                     menu: colorPicker
27                 },{
28             iconCls: 'add16',
29                     text: 'icon item'
30                 },{
31                     text: 'regular item'
32                 }]
33         });
34
35  * @xtype colormenu
36  * @author Nicolas Ferrero
37  */
38  Ext.define('Ext.menu.ColorPicker', {
39      extend: 'Ext.menu.Menu',
40
41      alias: 'widget.colormenu',
42
43      requires: [
44         'Ext.picker.Color'
45      ],
46
47     /**
48      * @cfg {Boolean} hideOnClick
49      * False to continue showing the menu after a date is selected, defaults to true.
50      */
51     hideOnClick : true,
52
53     /**
54      * @cfg {String} pickerId
55      * An id to assign to the underlying color picker. Defaults to <tt>null</tt>.
56      */
57     pickerId : null,
58
59     /**
60      * @cfg {Number} maxHeight
61      * @hide
62      */
63
64     /**
65      * The {@link Ext.picker.Color} instance for this ColorMenu
66      * @property picker
67      * @type ColorPicker
68      */
69
70     /**
71      * @event click
72      * @hide
73      */
74
75     /**
76      * @event itemclick
77      * @hide
78      */
79
80     initComponent : function(){
81         var me = this;
82
83         Ext.apply(me, {
84             plain: true,
85             showSeparator: false,
86             items: Ext.applyIf({
87                 cls: Ext.baseCSSPrefix + 'menu-color-item',
88                 id: me.pickerId,
89                 xtype: 'colorpicker'
90             }, me.initialConfig)
91         });
92
93         me.callParent(arguments);
94
95         me.picker = me.down('colorpicker');
96
97         /**
98          * @event select
99          * Fires when a date is selected from the {@link #picker Ext.picker.Color}
100          * @param {Ext.picker.Color} picker The {@link #picker Ext.picker.Color}
101          * @param {String} color The 6-digit color hex code (without the # symbol)
102          */
103         me.relayEvents(me.picker, ['select']);
104
105         if (me.hideOnClick) {
106             me.on('select', me.hidePickerOnSelect, me);
107         }
108     },
109
110     /**
111      * Hides picker on select if hideOnClick is true
112      * @private
113      */
114     hidePickerOnSelect: function() {
115         Ext.menu.Manager.hideAll();
116     }
117  });