8
0

theme.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import testUtils from 'ckeditor5-ui/tests/_utils/utils';
  7. import Collection from 'ckeditor5-utils/src/collection';
  8. import Model from 'ckeditor5-ui/src/model';
  9. import View from 'ckeditor5-ui/src/view';
  10. import Template from 'ckeditor5-ui/src/template';
  11. import IconView from 'ckeditor5-ui/src/icon/iconview';
  12. import ButtonView from 'ckeditor5-ui/src/button/buttonview';
  13. import createListDropdown from 'ckeditor5-ui/src/dropdown/list/createlistdropdown';
  14. import ToolbarView from 'ckeditor5-ui/src/toolbar/toolbarview';
  15. import boldIcon from 'ckeditor5-basic-styles/theme/icons/bold.svg';
  16. import italicIcon from 'ckeditor5-basic-styles/theme/icons/italic.svg';
  17. import '../../theme/theme.scss';
  18. testUtils.createTestUIView( {
  19. 'iconPlain1': '#icon-plain-1',
  20. 'iconPlain2': '#icon-plain-2',
  21. 'iconColor1': '#icon-color-1',
  22. 'iconColor2': '#icon-color-2',
  23. 'buttonStates': '#button-states',
  24. 'buttonTypes': '#button-types',
  25. 'buttonIcon': '#button-icon',
  26. 'buttonCustom': '#button-custom',
  27. 'buttonIconCustom': '#button-icon-custom',
  28. 'buttonIconStates': '#button-icon-states',
  29. 'buttonResponsive1': '#button-responsive-1',
  30. 'buttonResponsive2': '#button-responsive-2',
  31. 'buttonResponsive3': '#button-responsive-3',
  32. dropdown: '#dropdown',
  33. 'toolbarText': '#toolbar-text',
  34. 'toolbarButton': '#toolbar-button',
  35. 'toolbarRounded': '#toolbar-rounded',
  36. 'toolbarWrap': '#toolbar-wrap',
  37. 'toolbarSeparator': '#toolbar-separator',
  38. 'toolbarMultiRow': '#toolbar-multi-row',
  39. body: 'div#body'
  40. } ).then( ui => {
  41. renderIcon( ui );
  42. renderButton( ui );
  43. renderDropdown( ui );
  44. renderToolbar( ui );
  45. } );
  46. function renderIcon( ui ) {
  47. // --- In-text ------------------------------------------------------------
  48. ui.iconPlain1.add( icon( boldIcon ) );
  49. ui.iconPlain2.add( icon( italicIcon ) );
  50. ui.iconColor1.add( icon( boldIcon ) );
  51. ui.iconColor2.add( icon( italicIcon ) );
  52. }
  53. function renderButton( ui ) {
  54. // --- States ------------------------------------------------------------
  55. ui.buttonStates.add( button( {
  56. label: 'State: normal (none)',
  57. } ) );
  58. ui.buttonStates.add( button( {
  59. label: 'State: disabled',
  60. isEnabled: false
  61. } ) );
  62. ui.buttonStates.add( button( {
  63. label: 'State: on',
  64. isOn: true
  65. } ) );
  66. // --- Types ------------------------------------------------------------
  67. const actionButton = button( { label: 'Action button' } );
  68. const roundedButton = button( { label: 'Rounded corners' } );
  69. const boldButton = button( { label: 'Bold text' } );
  70. // TODO: It requires model interface.
  71. actionButton.element.classList.add( 'ck-button-action' );
  72. // TODO: It requires model interface.
  73. roundedButton.element.classList.add( 'ck-rounded-corners' );
  74. // TODO: It requires model interface.
  75. boldButton.element.classList.add( 'ck-button-bold' );
  76. ui.buttonTypes.add( actionButton );
  77. ui.buttonTypes.add( roundedButton );
  78. ui.buttonTypes.add( boldButton );
  79. // --- Icon ------------------------------------------------------------
  80. ui.buttonIcon.add( button( {
  81. label: 'Bold',
  82. icon: boldIcon
  83. } ) );
  84. const styledButton = button( {
  85. label: 'Button with an icon and custom styles',
  86. icon: italicIcon
  87. } );
  88. // TODO: It probably requires model interface.
  89. styledButton.element.setAttribute( 'style', 'border-radius: 100px; border: 0' );
  90. ui.buttonIconCustom.add( styledButton );
  91. ui.buttonIconStates.add( button( {
  92. label: 'Disabled',
  93. icon: boldIcon,
  94. isEnabled: false
  95. } ) );
  96. const disabledActionButton = button( {
  97. label: 'Disabled action',
  98. icon: boldIcon,
  99. isEnabled: false
  100. } );
  101. // TODO: It requires model interface.
  102. disabledActionButton.element.classList.add( 'ck-button-action' );
  103. ui.buttonIconStates.add( disabledActionButton );
  104. ui.buttonIconStates.add( button( {
  105. label: 'Bold',
  106. withText: false,
  107. icon: boldIcon
  108. } ) );
  109. // --- Responsive ------------------------------------------------------------
  110. for ( let i = 1; i < 4; i++ ) {
  111. ui[ `buttonResponsive${ i }` ].add( button( {
  112. label: 'A button',
  113. isEnabled: true
  114. } ) );
  115. ui[ `buttonResponsive${ i }` ].add( button( {
  116. label: 'Bold',
  117. icon: boldIcon,
  118. isEnabled: true
  119. } ) );
  120. const notextButton = button( {
  121. label: 'Bold',
  122. withText: false,
  123. icon: boldIcon
  124. } );
  125. // TODO: It requires model interface.
  126. notextButton.element.classList.add( 'ck-button-action' );
  127. ui[ `buttonResponsive${ i }` ].add( notextButton );
  128. }
  129. }
  130. function renderDropdown( ui ) {
  131. // --- ListDropdown ------------------------------------------------------------
  132. const collection = new Collection( { idProperty: 'label' } );
  133. [ 'Arial', 'Tahoma', 'Georgia' ].forEach( font => {
  134. collection.add( new Model( {
  135. label: font,
  136. style: `font-family: ${ font }`
  137. } ) );
  138. } );
  139. const itemListModel = new Model( {
  140. items: collection
  141. } );
  142. ui.dropdown.add( dropdown( {
  143. label: 'Normal state',
  144. isEnabled: true,
  145. content: itemListModel
  146. } ) );
  147. ui.dropdown.add( dropdown( {
  148. label: 'Disabled',
  149. isEnabled: false,
  150. content: itemListModel
  151. } ) );
  152. }
  153. function renderToolbar( ui ) {
  154. // --- Text ------------------------------------------------------------
  155. ui.toolbarText.add( toolbar( [
  156. icon( boldIcon ),
  157. text()
  158. ] ) );
  159. // --- Button ------------------------------------------------------------
  160. ui.toolbarButton.add( toolbar( [
  161. button(),
  162. text(),
  163. button( {
  164. label: 'Button with an icon',
  165. icon: boldIcon
  166. } ),
  167. dropdown(),
  168. button()
  169. ] ) );
  170. // --- Rounded ------------------------------------------------------------
  171. ui.toolbarRounded.add( toolbar( [
  172. button( {
  173. label: 'A button which corners are also rounded because of toolbar class'
  174. } ),
  175. button( {
  176. label: 'Button with an icon',
  177. icon: boldIcon
  178. } )
  179. ] ) );
  180. // --- Wrap ------------------------------------------------------------
  181. const wrapToolbar = toolbar( [
  182. button(),
  183. button(),
  184. button()
  185. ] );
  186. wrapToolbar.element.style.width = '150px';
  187. ui.toolbarWrap.add( wrapToolbar );
  188. // --- Separator ------------------------------------------------------------
  189. ui.toolbarSeparator.add( toolbar( [
  190. button(),
  191. button(),
  192. toolbarSeparator(),
  193. button( {
  194. label: 'Foo',
  195. icon: boldIcon
  196. } ),
  197. toolbarSeparator(),
  198. button( {
  199. label: 'Bar RTL',
  200. icon: boldIcon
  201. } )
  202. ] ) );
  203. // --- Multi row ------------------------------------------------------------
  204. ui.toolbarMultiRow.add( toolbar( [
  205. button(),
  206. button(),
  207. toolbarNewLine(),
  208. button( {
  209. label: 'Foo',
  210. icon: boldIcon
  211. } ),
  212. button( {
  213. label: 'Bar',
  214. icon: boldIcon
  215. } ),
  216. button( {
  217. label: 'Baz',
  218. icon: boldIcon
  219. } )
  220. ] ) );
  221. }
  222. const TextView = class extends View {
  223. constructor() {
  224. super();
  225. this.element = document.createTextNode( 'Sample text' );
  226. }
  227. };
  228. function text() {
  229. return new TextView();
  230. }
  231. function icon( content ) {
  232. const icon = new IconView();
  233. icon.content = content;
  234. return icon;
  235. }
  236. function button( {
  237. label = 'Button',
  238. isEnabled = true,
  239. isOn = false,
  240. withText = true,
  241. icon
  242. } = {} ) {
  243. const button = new ButtonView();
  244. button.set( { label, isEnabled, isOn, withText, icon } );
  245. return button;
  246. }
  247. function toolbar( children = [] ) {
  248. const toolbar = new ToolbarView();
  249. children.forEach( c => toolbar.items.add( c ) );
  250. return toolbar;
  251. }
  252. function dropdown( {
  253. label = 'Dropdown',
  254. isEnabled = true,
  255. isOn = false,
  256. withText = true,
  257. items = new Collection( { idProperty: 'label' } )
  258. } = {} ) {
  259. const model = new Model( { label, isEnabled, items, isOn, withText } );
  260. const dropdown = createListDropdown( model, {} );
  261. return dropdown;
  262. }
  263. const ToolbarSeparatorView = class extends View {
  264. constructor() {
  265. super();
  266. this.template = new Template( {
  267. tag: 'span',
  268. attributes: {
  269. class: 'ck-toolbar-separator'
  270. }
  271. } );
  272. }
  273. };
  274. function toolbarSeparator() {
  275. return new ToolbarSeparatorView();
  276. }
  277. const ToolbarNewlineView = class extends View {
  278. constructor() {
  279. super();
  280. this.template = new Template( {
  281. tag: 'span',
  282. attributes: {
  283. class: 'ck-toolbar-newline'
  284. }
  285. } );
  286. }
  287. };
  288. function toolbarNewLine() {
  289. return new ToolbarNewlineView();
  290. }