Permalink
Browse files

[feature] widget: improved the use of the stylers for the accordion

  • Loading branch information...
1 parent f33b7cc commit f146f261659637f65a622eb20818eae855deb185 Jessica Castejon committed Jun 23, 2011
Showing with 21 additions and 11 deletions.
  1. +21 −11 stdlib/widgets/accordion/accordion.opa
@@ -45,8 +45,10 @@ import stdlib.widgets.core
type WAccordion.config = {
close_others : bool /** Defines if at the opening of one tab the other open tabs should be closed */
global_style : WStyler.styler /** Global CSS style of the widget */
- open_style : WStyler.styler /** CSS style of the tab when it is open*/
- close_style : WStyler.styler /** CSS style of the tab when it is closed */
+ tab_open_style : WStyler.styler /** CSS style of the tab when it is open*/
+ tab_close_style : WStyler.styler /** CSS style of the tab when it is closed */
+ open_style : WStyler.styler /** CSS style of the content of a tab when it is open*/
+ close_style : WStyler.styler /** CSS style of the content of a tab when it is closed */
tab_content_style : WStyler.styler /** CSS style of the content of a tab */
}
@private
@@ -68,7 +70,10 @@ WAccordion = {{
global_style = WStyler.make_style(css {
font-family: Verdana;
font-size: 12px;
- color: #696969;})
+ color: #696969;
+ border: 1px solid #000000;})
+ tab_open_style = WStyler.empty
+ tab_close_style = WStyler.empty
open_style = WStyler.empty
close_style = WStyler.empty
tab_content_style = WStyler.empty
@@ -85,7 +90,9 @@ WAccordion = {{
*@return The HTML corresponding to the widget
*/
html(config: WAccordion.config, id: string, tab_content: list((string, string, string))): xhtml =
- <div id=#{id}>{get_tabs(config,tab_content,id)}</div>
+ widget = <div id=#{id}>{get_tabs(config,tab_content,id)}</div>
+ widget = WStyler.add(config.global_style,widget)
+ <>{widget}</>
/**
*Function that opens a closed tab
@@ -116,13 +123,15 @@ WAccordion = {{
@private
get_tabs(config: WAccordion.config, tab_content: list((string,string,string)), id: string): list(xhtml) =
add_tab(i,(num,title,content))=
- (class,style) = if i==0
- then (internal_opa_open,WStyler.merge([config.open_style,WStyler.make_style([Css_build.display_block])]))
- else (internal_opa_close,WStyler.merge([config.close_style,WStyler.make_style([Css_build.display_none])]))
+ (class,style,tab_style) = if i==0
+ then (internal_opa_open,WStyler.merge([config.tab_content_style,config.open_style,WStyler.make_style([Css_build.display_block])]),config.tab_open_style)
+ else (internal_opa_close,WStyler.merge([config.tab_content_style,config.close_style,WStyler.make_style([Css_build.display_none])]),config.tab_close_style)
block_content = <div id="{num}_content">{content}</div>
block_content = WStyler.add(style,block_content)
+ block_title = <div id="{num}_title" onclick={_ -> clicked_title(id,num,config)}>{title}</div>
+ block_title = WStyler.add(tab_style,block_title)
<div id=#{num} class="{class}">
- <div id="{num}_title" onclick={_ -> clicked_title(id,num,config)}>{title}</div>
+ {block_title}
{block_content}
</div>
List.mapi(add_tab,tab_content)
@@ -168,13 +177,14 @@ WAccordion = {{
@private
apply_change(config: WAccordion.config, dom_content: dom, dom_container: dom, id: string, action: WAccordion.private.mode): void =
- (remove_class,add_class,style,action)=
+ (remove_class,add_class,style,tab_style,action)=
if action=={close}
- then (internal_opa_open,internal_opa_close,config.close_style,Dom.transition(_,Dom.Effect.hide()))
- else (internal_opa_close,internal_opa_open,config.open_style,Dom.transition(_,Dom.Effect.slide_in()))
+ then (internal_opa_open,internal_opa_close,config.close_style,config.tab_close_style,Dom.transition(_,Dom.Effect.hide()))
+ else (internal_opa_close,internal_opa_open,config.open_style,config.tab_open_style,Dom.transition(_,Dom.Effect.slide_in()))
do Dom.remove_class(dom_container,remove_class)
do Dom.add_class(dom_container,add_class)
do WStyler.set_dom(style,"{id}_content")
+ do WStyler.set_dom(tab_style,"{id}_title")
_ = action(dom_content)
void
}}

0 comments on commit f146f26

Please sign in to comment.