grid.js 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. (function (factory) {
  2. if (typeof module === "object" && typeof module.exports === "object") {
  3. var v = factory(require, exports);
  4. if (v !== undefined) module.exports = v;
  5. }
  6. else if (typeof define === "function" && define.amd) {
  7. define(["require", "exports", "@angular/core"], factory);
  8. }
  9. })(function (require, exports) {
  10. "use strict";
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var core_1 = require("@angular/core");
  13. /**
  14. * @name Grid
  15. * @module ionic
  16. * @description
  17. *
  18. * The grid is a powerful mobile-first flexbox system for building custom layouts.
  19. * It is heavily influenced by [Bootstrap's grid system](http://v4-alpha.getbootstrap.com/layout/grid/).
  20. *
  21. * The grid is composed of three units — a grid, row(s) and column(s). Columns will expand to fill their
  22. * row, and will resize to fit additional columns. It is based on a 12 column layout with different
  23. * breakpoints based on the screen size. The number of columns and breakpoints can be fully customized
  24. * using Sass.
  25. *
  26. * - [How it works](#how-it-works)
  27. * - [Grid size](#grid-size)
  28. * - [Grid attributes](#grid-attributes)
  29. * - [Default breakpoints](#default-breakpoints)
  30. * - [Auto-layout columns](#auto-layout-columns)
  31. * - [Equal-width](#equal-width)
  32. * - [Setting one column width](#setting-one-column-width)
  33. * - [Variable-width](#variable-width)
  34. * - [Responsive attributes](#responsive-attributes)
  35. * - [All breakpoints](#all-breakpoints)
  36. * - [Stacked to horizontal](#stacked-to-horizontal)
  37. * - [Reordering](#reordering)
  38. * - [Offsetting columns](#offsetting-columns)
  39. * - [Push and pull](#push-and-pull)
  40. * - [Alignment](#alignment)
  41. * - [Vertical Alignment](#vertical-alignment)
  42. * - [Horizontal Alignment](#horizontal-alignment)
  43. * - [Customizing the grid](#customizing-the-grid)
  44. * - [Number of columns and padding](#number-of-columns-and-padding)
  45. * - [Grid tiers](#grid-tiers)
  46. *
  47. *
  48. * ## How it works
  49. *
  50. * The grid is a mobile-first system made up of any number of rows and columns.
  51. * It is built with flexbox making it extremely responsive. The components that
  52. * make up the grid can be written as an element (e.g., `<ion-grid>`) or added as
  53. * an attribute to any element (e.g., `<div ion-row>`).
  54. *
  55. * Here's how it works:
  56. *
  57. * - Grids act as a container for all rows and columns. Grids take up the full width of their container,
  58. * but adding the `fixed` attribute will specify the width per screen size, see [grid size](#grid-size) below.
  59. * - Rows are horizontal groups of columns that line the columns up properly.
  60. * - Content should be placed within columns, and only columns may be immediate children of rows.
  61. * - Grid columns without a specified width will automatically have equal widths.
  62. * For example, four instances of `col-sm` will each automatically be 25% wide for small breakpoints.
  63. * - Column attributes indicate the number of columns to use out of the default 12 per row.
  64. * So, `col-4` can be added in order to have three equal-width columns.
  65. * - Column widths are set as a percentage, so they’re always fluid and sized relative to their parent element.
  66. * - Columns have padding between individual columns, however, the padding can be removed from the grid and
  67. * columns by adding `no-padding` on the grid.
  68. * - There are five grid tiers by default, one for each responsive breakpoint: all breakpoints (extra small),
  69. * small, medium, large, and extra large.
  70. * - Grid tiers are based on minimum widths, meaning they apply to their tier and all those larger than it
  71. * (e.g., `col-sm-4` applies to small, medium, large, and extra large devices).
  72. * - Grids can easily be customized via Sass variables. See [customizing the grid](#customizing-the-grid).
  73. *
  74. * There are some [known bugs with flexbox](https://github.com/philipwalton/flexbugs) that
  75. * should be checked prior to creating issues with Ionic.
  76. *
  77. * ## Grid size
  78. *
  79. * By default, the grid will take up 100% width. To set a maximum width based on the screen
  80. * size add the `fixed` attribute. The maximum width of the grid for each breakpoint is defined
  81. * in the `$grid-max-widths` Sass variable. For more information, see
  82. * [customizing the grid](#customizing-the-grid).
  83. *
  84. * | Name | Value | Description |
  85. * |----------|----------|-----------------------------------------------------|
  86. * | xs | auto | Don't set the grid width for xs screens |
  87. * | sm | 540px | Set grid width to 540px when (min-width: 576px) |
  88. * | md | 720px | Set grid width to 720px when (min-width: 768px) |
  89. * | lg | 960px | Set grid width to 960px when (min-width: 992px) |
  90. * | xl | 1140px | Set grid width to 1140px when (min-width: 1200px) |
  91. *
  92. *
  93. * ## Grid attributes
  94. *
  95. * The grid takes up full width and has padding added to it based on the screen size. There are two
  96. * attributes that can be used to adjust this behavior.
  97. *
  98. * | Property | Description |
  99. * |-----------------|-------------------------------------------------------------------------------------------------------------------|
  100. * | no-padding | Removes padding from the grid and immediate children columns. |
  101. * | fixed | Set a max width based on the screen size. |
  102. *
  103. *
  104. * ## Default breakpoints
  105. *
  106. * The default breakpoints are defined by the `$grid-breakpoints` Sass variable. It can be
  107. * customized to use different values for the breakpoint, rename and add/remove breakpoints.
  108. * For more information, see [customizing the grid](#customizing-the-grid).
  109. *
  110. * | Name | Value | Width Prefix | Offset Prefix | Push Prefix | Pull Prefix | Description |
  111. * |----------|----------|--------------|---------------|--------------|-------------|---------------------------------------------------|
  112. * | xs | 0 | `col-` | `offset-` | `push-` | `pull-` | Set columns when (min-width: 0) |
  113. * | sm | 576px | `col-sm-` | `offset-sm-` | `push-sm-` | `pull-sm-` | Set columns when (min-width: 576px) |
  114. * | md | 768px | `col-md-` | `offset-md-` | `push-md-` | `pull-md-` | Set columns when (min-width: 768px) |
  115. * | lg | 992px | `col-lg-` | `offset-lg-` | `push-lg-` | `pull-lg-` | Set columns when (min-width: 992px) |
  116. * | xl | 1200px | `col-xl-` | `offset-xl-` | `push-xl-` | `pull-xl-` | Set columns when (min-width: 1200px) |
  117. *
  118. * _Note: the first breakpoint must have the value set to 0 and all breakpoint values must be in
  119. * ascending order._
  120. *
  121. * ## Auto-layout columns
  122. *
  123. * ### Equal-width
  124. *
  125. * By default, columns will take up equal width inside of a row for all devices and screen sizes.
  126. *
  127. * ```
  128. * <ion-grid>
  129. * <ion-row>
  130. * <ion-col>
  131. * 1 of 2
  132. * </ion-col>
  133. * <ion-col>
  134. * 2 of 2
  135. * </ion-col>
  136. * </ion-row>
  137. * <ion-row>
  138. * <ion-col>
  139. * 1 of 3
  140. * </ion-col>
  141. * <ion-col>
  142. * 2 of 3
  143. * </ion-col>
  144. * <ion-col>
  145. * 3 of 3
  146. * </ion-col>
  147. * </ion-row>
  148. * </ion-grid>
  149. * ```
  150. *
  151. * ### Setting one column width
  152. *
  153. * Set the width of one column and the others will automatically resize around it.
  154. * This can be done using our predefined grid attributes. In the example below,
  155. * the other columns will resize no matter the width of the center column.
  156. *
  157. * ```
  158. * <ion-grid>
  159. * <ion-row>
  160. * <ion-col>
  161. * 1 of 3
  162. * </ion-col>
  163. * <ion-col col-8>
  164. * 2 of 3 (wider)
  165. * </ion-col>
  166. * <ion-col>
  167. * 3 of 3
  168. * </ion-col>
  169. * </ion-row>
  170. * <ion-row>
  171. * <ion-col>
  172. * 1 of 3
  173. * </ion-col>
  174. * <ion-col col-6>
  175. * 2 of 3 (wider)
  176. * </ion-col>
  177. * <ion-col>
  178. * 3 of 3
  179. * </ion-col>
  180. * </ion-row>
  181. * </ion-grid>
  182. * ```
  183. *
  184. * ### Variable-width
  185. *
  186. * Using the `col-{breakpoint}-auto` attributes, the column can size itself based on the
  187. * natural width of its content. This is extremely useful for setting a column width
  188. * using pixels. The columns next to the variable-width column will resize to fill the row.
  189. *
  190. * ```
  191. * <ion-grid>
  192. * <ion-row>
  193. * <ion-col>
  194. * 1 of 3
  195. * </ion-col>
  196. * <ion-col col-auto>
  197. * Variable width content
  198. * </ion-col>
  199. * <ion-col>
  200. * 3 of 3
  201. * </ion-col>
  202. * </ion-row>
  203. * <ion-row>
  204. * <ion-col>
  205. * 1 of 4
  206. * </ion-col>
  207. * <ion-col>
  208. * 2 of 4
  209. * </ion-col>
  210. * <ion-col col-auto>
  211. * <ion-input placeholder="Variable width input"></ion-input>
  212. * </ion-col>
  213. * <ion-col>
  214. * 4 of 4
  215. * </ion-col>
  216. * </ion-row>
  217. * </ion-grid>
  218. * ```
  219. *
  220. *
  221. * ## Responsive attributes
  222. *
  223. * ### All breakpoints
  224. *
  225. * To customize a column's width for all devices and screens, add the `col-*`
  226. * attribute. These attributes tell the column to take up `*` columns out
  227. * of the available columns.
  228. *
  229. * ```
  230. * <ion-grid>
  231. * <ion-row>
  232. * <ion-col col-4>
  233. * 1 of 4
  234. * </ion-col>
  235. * <ion-col col-2>
  236. * 2 of 4
  237. * </ion-col>
  238. * <ion-col col-2>
  239. * 3 of 4
  240. * </ion-col>
  241. * <ion-col col-4>
  242. * 4 of 4
  243. * </ion-col>
  244. * </ion-row>
  245. * </ion-grid>
  246. * ```
  247. *
  248. * ### Stacked to horizontal
  249. *
  250. * Use a combination of width and breakpoint attributes to create a grid that starts out stacked
  251. * on extra small screens before becoming horizontal on small screens.
  252. *
  253. * ```
  254. * <ion-grid>
  255. * <ion-row>
  256. * <ion-col col-12 col-sm>
  257. * 1 of 4
  258. * </ion-col>
  259. * <ion-col col-12 col-sm>
  260. * 2 of 4
  261. * </ion-col>
  262. * <ion-col col-12 col-sm>
  263. * 3 of 4
  264. * </ion-col>
  265. * <ion-col col-12 col-sm>
  266. * 4 of 4
  267. * </ion-col>
  268. * </ion-row>
  269. * </ion-grid>
  270. * ```
  271. *
  272. *
  273. * ## Reordering
  274. *
  275. * ### Offsetting columns
  276. *
  277. * Move columns to the right by adding the `offset-*` attributes. These attributes
  278. * increase the margin start of the column by `*` columns. For example, in the following
  279. * grid the last column will be offset by 3 columns and take up 3 columns:
  280. *
  281. * ```
  282. * <ion-grid>
  283. * <ion-row>
  284. * <ion-col col-3>
  285. * 1 of 2
  286. * </ion-col>
  287. * <ion-col col-3 offset-3>
  288. * 2 of 2
  289. * </ion-col>
  290. * </ion-row>
  291. * </ion-grid>
  292. * ```
  293. *
  294. * Offsets can also be added based on screen breakpoints. Here's an example of a
  295. * grid where the last column will be offset by 3 columns for `md` screens and up:
  296. *
  297. * ```
  298. * <ion-grid>
  299. * <ion-row>
  300. * <ion-col col-md-3>
  301. * 1 of 3
  302. * </ion-col>
  303. * <ion-col col-md-3>
  304. * 2 of 3
  305. * </ion-col>
  306. * <ion-col col-md-3 offset-md-3>
  307. * 3 of 3
  308. * </ion-col>
  309. * </ion-row>
  310. * </ion-grid>
  311. * ```
  312. *
  313. * ### Push and pull
  314. *
  315. * Reorder the columns by adding the `push-*` and `pull-*` attributes. These attributes
  316. * adjust the `left` and `right` of the columns by `*` columns making it easy to reorder
  317. * columns. For example, in the following grid the column with the `1st col` description
  318. * will actually be the last column and the `2nd col` will be the first column.
  319. *
  320. * ```
  321. * <ion-grid>
  322. * <ion-row>
  323. * <ion-col col-9 push-3>
  324. * 1 of 2
  325. * </ion-col>
  326. * <ion-col col-3 pull-9>
  327. * 2 of 2
  328. * </ion-col>
  329. * </ion-row>
  330. * </ion-grid>
  331. * ```
  332. *
  333. * Push and pull can also be added based on screen breakpoints. In the following example,
  334. * the column with the `3rd` column description will actually be the first column for
  335. * `md` screens and up:
  336. *
  337. * ```
  338. * <ion-grid>
  339. * <ion-row>
  340. * <ion-col col-md-6 push-md-3>
  341. * 1 of 3
  342. * </ion-col>
  343. * <ion-col col-md-3 push-md-3>
  344. * 2 of 3
  345. * </ion-col>
  346. * <ion-col col-md-3 pull-md-9>
  347. * 3 of 3
  348. * </ion-col>
  349. * </ion-row>
  350. * </ion-grid>
  351. * ```
  352. *
  353. *
  354. * ## Alignment
  355. *
  356. * ### Vertical alignment
  357. *
  358. * All columns can be vertically aligned inside of a row by adding different
  359. * attributes to the row. For a list of available attributes, see
  360. * [row attributes](../Row#row-attributes).
  361. *
  362. * ```
  363. * <ion-grid>
  364. * <ion-row align-items-start>
  365. * <ion-col>
  366. * 1 of 4
  367. * </ion-col>
  368. * <ion-col>
  369. * 2 of 4
  370. * </ion-col>
  371. * <ion-col>
  372. * 3 of 4
  373. * </ion-col>
  374. * <ion-col>
  375. * 4 of 4 <br>#<br>#<br>#
  376. * </ion-col>
  377. * </ion-row>
  378. *
  379. * <ion-row align-items-center>
  380. * <ion-col>
  381. * 1 of 4
  382. * </ion-col>
  383. * <ion-col>
  384. * 2 of 4
  385. * </ion-col>
  386. * <ion-col>
  387. * 3 of 4
  388. * </ion-col>
  389. * <ion-col>
  390. * 4 of 4 <br>#<br>#<br>#
  391. * </ion-col>
  392. * </ion-row>
  393. *
  394. * <ion-row align-items-end>
  395. * <ion-col>
  396. * 1 of 4
  397. * </ion-col>
  398. * <ion-col>
  399. * 2 of 4
  400. * </ion-col>
  401. * <ion-col>
  402. * 3 of 4
  403. * </ion-col>
  404. * <ion-col>
  405. * 4 of 4 <br>#<br>#<br>#
  406. * </ion-col>
  407. * </ion-row>
  408. * </ion-grid>
  409. * ```
  410. *
  411. * Columns can also align themselves differently than other columns by
  412. * adding the alignment attribute directly to the column. For a list of available
  413. * attributes, see [column attributes](../Col#column-attributes).
  414. *
  415. * ```
  416. * <ion-grid>
  417. * <ion-row>
  418. * <ion-col align-self-start>
  419. * <div>
  420. * 1 of 4
  421. * </div>
  422. * </ion-col>
  423. * <ion-col align-self-center>
  424. * <div>
  425. * 2 of 4
  426. * </div>
  427. * </ion-col>
  428. * <ion-col align-self-end>
  429. * <div>
  430. * 3 of 4
  431. * </div>
  432. * </ion-col>
  433. * <ion-col>
  434. * <div>
  435. * 4 of 4 <br>#<br>#<br>#
  436. * </div>
  437. * </ion-col>
  438. * </ion-row>
  439. * </ion-grid>
  440. * ```
  441. *
  442. * ### Horizontal alignment
  443. *
  444. * All columns can be horizontally aligned inside of a row by adding different
  445. * attributes to the row. For a list of available attributes, see
  446. * [row attributes](../Row#row-attributes).
  447. *
  448. * ```
  449. * <ion-grid>
  450. * <ion-row justify-content-start>
  451. * <ion-col col-3>
  452. * 1 of 2
  453. * </ion-col>
  454. * <ion-col col-3>
  455. * 2 of 2
  456. * </ion-col>
  457. * </ion-row>
  458. *
  459. * <ion-row justify-content-center>
  460. * <ion-col col-3>
  461. * 1 of 2
  462. * </ion-col>
  463. * <ion-col col-3>
  464. * 2 of 2
  465. * </ion-col>
  466. * </ion-row>
  467. *
  468. * <ion-row justify-content-end>
  469. * <ion-col col-3>
  470. * 1 of 2
  471. * </ion-col>
  472. * <ion-col col-3>
  473. * 2 of 2
  474. * </ion-col>
  475. * </ion-row>
  476. *
  477. * <ion-row justify-content-around>
  478. * <ion-col col-3>
  479. * 1 of 2
  480. * </ion-col>
  481. * <ion-col col-3>
  482. * 2 of 2
  483. * </ion-col>
  484. * </ion-row>
  485. *
  486. * <ion-row justify-content-between>
  487. * <ion-col col-3>
  488. * 1 of 2
  489. * </ion-col>
  490. * <ion-col col-3>
  491. * 2 of 2
  492. * </ion-col>
  493. * </ion-row>
  494. * </ion-grid>
  495. * ```
  496. *
  497. *
  498. * ## Customizing the grid
  499. *
  500. * Using our built-in grid Sass variables and maps, it’s possible to completely customize
  501. * the predefined grid attributes. Change the number of breakpoints, the media query values,
  502. * the number of columns, and more.
  503. *
  504. * ### Number of columns and padding
  505. *
  506. * The number of grid columns and their padding can be modified via Sass variables.
  507. * `$grid-columns` is used to generate the widths (in percent) of each individual column.
  508. * `$grid-padding-width` is used for the padding on the grid, while `$grid-padding-widths`
  509. * allows breakpoint-specific widths that are divided evenly across `padding-left` and
  510. * `padding-right` as well as `padding-top` and `padding-bottom` of the grid and columns.
  511. *
  512. * ```
  513. * $grid-columns: 12 !default;
  514. *
  515. * $grid-padding-width: 10px !default;
  516. *
  517. * $grid-padding-widths: (
  518. * xs: $grid-padding-width,
  519. * sm: $grid-padding-width,
  520. * md: $grid-padding-width,
  521. * lg: $grid-padding-width,
  522. * xl: $grid-padding-width
  523. * ) !default;
  524. * ```
  525. *
  526. * ### Grid tiers
  527. *
  528. * To customize the breakpoints and their values, override the values of
  529. * `$grid-breakpoints` and `$grid-max-widths`. For example, to only use
  530. * 3 breakpoints, the following could be written:
  531. *
  532. * ```
  533. * $grid-breakpoints: (
  534. * sm: 0,
  535. * md: 768px,
  536. * lg: 1024px
  537. * );
  538. *
  539. * $grid-max-widths: (
  540. * sm: 420px,
  541. * md: 720px,
  542. * lg: 960px
  543. * );
  544. * ```
  545. *
  546. */
  547. var Grid = (function () {
  548. function Grid() {
  549. }
  550. Grid.decorators = [
  551. { type: core_1.Directive, args: [{
  552. selector: 'ion-grid, [ion-grid]',
  553. host: {
  554. 'class': 'grid'
  555. }
  556. },] },
  557. ];
  558. /** @nocollapse */
  559. Grid.ctorParameters = function () { return []; };
  560. return Grid;
  561. }());
  562. exports.Grid = Grid;
  563. });
  564. //# sourceMappingURL=grid.js.map