|
| 1 | +/** |
| 2 | + * @parent bit-docs-generate-html/styles |
| 3 | + * @page bit-docs-generate-html/styles/mixins mixins |
| 4 | + * @group bit-docs-generate-html/styles/mixins/helper #helper |
| 5 | + * |
| 6 | + * @description Mixins for site-wide visual layout. |
| 7 | + * |
| 8 | + * @body |
| 9 | + * |
| 10 | + * Mixins are useful as reusable rules that can be added into any declaration. |
| 11 | + */ |
| 12 | + |
| 13 | +#helper { |
| 14 | + /** |
| 15 | + * @function bit-docs-generate-html/styles/mixins/helper/padding .padding |
| 16 | + * @parent bit-docs-generate-html/styles/mixins/helper |
| 17 | + * |
| 18 | + * Sets padding for passed sides. |
| 19 | + * |
| 20 | + * @signature `#helper.padding(@sides; @amount: @defaultPadding)` |
| 21 | + * |
| 22 | + * @param {String} @sides A space-separated list of "sides", like `left right`. |
| 23 | + * |
| 24 | + * @param {Number} @amount An amount of padding in pixels, defaults to |
| 25 | + * [bit-docs-generate-html/styles/variables/@defaultPadding @defaultPadding]. |
| 26 | + * |
| 27 | + * @body |
| 28 | + * |
| 29 | + * ### Use |
| 30 | + * |
| 31 | + * ```less |
| 32 | + * .container { |
| 33 | + * #helper.padding(left right; 50px); |
| 34 | + * } |
| 35 | + * ``` |
| 36 | + */ |
| 37 | + .padding(@sides; @amount: @defaultPadding) { |
| 38 | + .property-names(padding; @sides; @amount); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @function bit-docs-generate-html/styles/mixins/helper/flex .flex |
| 43 | + * @parent bit-docs-generate-html/styles/mixins/helper |
| 44 | + * |
| 45 | + * Sets flexbox "grow" and "shrink" in most compatible way. |
| 46 | + * |
| 47 | + * @signature `#helper.flex(@grow: 0, @shrink: 1)` |
| 48 | + * |
| 49 | + * @param {Number} @grow The amount this flex item should grow, defaults to 0. |
| 50 | + * |
| 51 | + * @param {Number} @shrink The amount this flex item should shrink, defaults to 1. |
| 52 | + * |
| 53 | + * @body |
| 54 | + * |
| 55 | + * ### Use |
| 56 | + * |
| 57 | + * ```less |
| 58 | + * .flex-none { |
| 59 | + * #helper.flex(0; 0); |
| 60 | + * } |
| 61 | + * ``` |
| 62 | + */ |
| 63 | + .flex(@grow: 0, @shrink: 1) { |
| 64 | + -webkit-box-flex: @grow; |
| 65 | + -webkit-flex: @grow @shrink auto; |
| 66 | + -moz-box-flex: @grow; |
| 67 | + -ms-flex: @grow @shrink auto; |
| 68 | + flex: @grow @shrink auto; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @function bit-docs-generate-html/styles/mixins/helper/property-names .property-names |
| 73 | + * @parent bit-docs-generate-html/styles/mixins/helper |
| 74 | + * @hide |
| 75 | + * |
| 76 | + * Helper for setting multiple dash properties to same value. |
| 77 | + * |
| 78 | + * @signature `#helper.property-names(@p; @s; @v)` |
| 79 | + * |
| 80 | + * @param {String} @p The property name to prepend before the dash and string. |
| 81 | + * |
| 82 | + * @param {String} @s A space-separated list of strings to iterate over. |
| 83 | + * |
| 84 | + * @param {Number} @v The value to set each concatenated property to. |
| 85 | + * |
| 86 | + * @body |
| 87 | + * |
| 88 | + * ### Use |
| 89 | + * |
| 90 | + * ```less |
| 91 | + * .top-left-margin { |
| 92 | + * .property-names(margin; top left; 100px); |
| 93 | + * } |
| 94 | + * |
| 95 | + * .special img { |
| 96 | + * .top-left-margin; |
| 97 | + * } |
| 98 | + * ``` |
| 99 | + */ |
| 100 | + .property-names(@p; @s; @v) { |
| 101 | + .-(@i: length(@s)) when (@i > 0) { |
| 102 | + @n: extract(@s, @i); |
| 103 | + & {@{p}-@{n}: @v} |
| 104 | + .-((@i - 1)); |
| 105 | + } .-; |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +// Flexbox (flexbugs: https://github.com/philipwalton/flexbugs) |
| 110 | + |
| 111 | +/** |
| 112 | + * @property .display-flex |
| 113 | + * @parent bit-docs-generate-html/styles/mixins |
| 114 | + * |
| 115 | + * Sets the display to flex using vendor prefixes. |
| 116 | + * |
| 117 | + * @body |
| 118 | + * |
| 119 | + * ### Use |
| 120 | + * |
| 121 | + * ```less |
| 122 | + * body { |
| 123 | + * .display-flex; |
| 124 | + * } |
| 125 | + * ``` |
| 126 | + */ |
| 127 | +.display-flex { |
| 128 | + display: -webkit-box; |
| 129 | + display: -webkit-flex; |
| 130 | + display: -moz-box; |
| 131 | + display: -ms-flexbox; |
| 132 | + display: flex; |
| 133 | +} |
| 134 | + |
| 135 | +/** |
| 136 | + * @property .flex-row |
| 137 | + * @parent bit-docs-generate-html/styles/mixins |
| 138 | + * |
| 139 | + * Sets the display to flex and direction to row using vendor prefixes. |
| 140 | + * |
| 141 | + * @body |
| 142 | + * |
| 143 | + * ### Use |
| 144 | + * |
| 145 | + * ```less |
| 146 | + * body { |
| 147 | + * .flex-row; |
| 148 | + * } |
| 149 | + * ``` |
| 150 | + */ |
| 151 | +.flex-row { |
| 152 | + .display-flex; |
| 153 | + -webkit-box-orient: horizontal; |
| 154 | + -webkit-box-direction: normal; |
| 155 | + -webkit-flex-direction: row; |
| 156 | + -moz-box-orient: horizontal; |
| 157 | + -moz-box-direction: normal; |
| 158 | + -ms-flex-direction: row; |
| 159 | + flex-direction: row; |
| 160 | +} |
| 161 | + |
| 162 | +/** |
| 163 | + * @property .flex-column |
| 164 | + * @parent bit-docs-generate-html/styles/mixins |
| 165 | + * |
| 166 | + * Sets the display to flex and direction to column using vendor prefixes. |
| 167 | + * |
| 168 | + * @body |
| 169 | + * |
| 170 | + * ### Use |
| 171 | + * |
| 172 | + * ```less |
| 173 | + * body { |
| 174 | + * .flex-column; |
| 175 | + * } |
| 176 | + * ``` |
| 177 | + */ |
| 178 | +.flex-column { |
| 179 | + .display-flex; |
| 180 | + -webkit-box-orient: vertical; |
| 181 | + -webkit-box-direction: normal; |
| 182 | + -webkit-flex-direction: column; |
| 183 | + -moz-box-orient: vertical; |
| 184 | + -moz-box-direction: normal; |
| 185 | + -ms-flex-direction: column; |
| 186 | + flex-direction: column; |
| 187 | +} |
| 188 | + |
| 189 | +/** |
| 190 | + * @property .flex-initial |
| 191 | + * @parent bit-docs-generate-html/styles/mixins |
| 192 | + * |
| 193 | + * Emulates `flex: initial;` in a compatible way using vendor prefixes. |
| 194 | + * |
| 195 | + * @body |
| 196 | + * |
| 197 | + * ### Use |
| 198 | + * |
| 199 | + * ```less |
| 200 | + * body { |
| 201 | + * .flex-initial; |
| 202 | + * } |
| 203 | + * ``` |
| 204 | + */ |
| 205 | +.flex-initial { |
| 206 | + #helper.flex(); |
| 207 | +} |
| 208 | + |
| 209 | +/** |
| 210 | + * @property .flex-auto |
| 211 | + * @parent bit-docs-generate-html/styles/mixins |
| 212 | + * |
| 213 | + * Emulates `flex: auto;` in a compatible way using vendor prefixes. |
| 214 | + * |
| 215 | + * @body |
| 216 | + * |
| 217 | + * ### Use |
| 218 | + * |
| 219 | + * ```less |
| 220 | + * body { |
| 221 | + * .flex-auto; |
| 222 | + * } |
| 223 | + * ``` |
| 224 | + */ |
| 225 | +.flex-auto { |
| 226 | + #helper.flex(1); |
| 227 | +} |
| 228 | + |
| 229 | +/** |
| 230 | + * @property .flex-none |
| 231 | + * @parent bit-docs-generate-html/styles/mixins |
| 232 | + * |
| 233 | + * Emulates `flex: none;` in a compatible way using vendor prefixes. |
| 234 | + * |
| 235 | + * @body |
| 236 | + * |
| 237 | + * ### Use |
| 238 | + * |
| 239 | + * ```less |
| 240 | + * body { |
| 241 | + * .flex-none; |
| 242 | + * } |
| 243 | + * ``` |
| 244 | + */ |
| 245 | +.flex-none { |
| 246 | + #helper.flex(0; 0); |
| 247 | +} |
0 commit comments