Utility API
Yordamchi API yordam dasturi sinflarini yaratish uchun Sass-ga asoslangan vositadir.
Bootstrap yordam dasturlari bizning API yordamchi dasturimiz yordamida yaratiladi va ular Sass orqali standart yordamchi dasturlar to'plamini o'zgartirish yoki kengaytirish uchun ishlatilishi mumkin. Bizning yordamchi dasturimiz turli xil variantlarga ega sinflar oilalarini yaratish uchun Sass xaritalari va funktsiyalari seriyasiga asoslangan. Agar siz Sass xaritalari bilan tanish bo'lmasangiz, boshlash uchun rasmiy Sass hujjatlarini o'qing .
Xarita $utilities
barcha yordamchi dasturlarimizni o'z ichiga oladi va agar mavjud bo'lsa, keyinchalik sizning shaxsiy $utilities
xaritangiz bilan birlashtiriladi. Yordamchi dasturlar xaritasi quyidagi variantlarni qabul qiladigan yordamchi dasturlarning kalitli ro'yxatini o'z ichiga oladi:
Variant | Turi | Standart qiymat | Tavsif |
---|---|---|---|
property |
Majburiy | - | Xususiyat nomi, bu satr yoki qatorlar massivi bo'lishi mumkin (masalan, gorizontal to'ldirishlar yoki chekkalar). |
values |
Majburiy | - | Qiymatlar roʻyxati yoki sinf nomi qiymat bilan bir xil boʻlishini xohlamasangiz, xarita. Agar null xarita kaliti sifatida foydalanilsa, u kompilyatsiya qilinmaydi. |
class |
Ixtiyoriy | null | Yaratilgan sinf nomi. Agar taqdim etilmagan bo'lsa va property satrlar massivi bo'lsa, class sukut bo'yicha property massivning birinchi elementi bo'ladi. |
css-var |
Ixtiyoriy | false |
CSS qoidalari o'rniga CSS o'zgaruvchilarini yaratish uchun mantiqiy. |
local-vars |
Ixtiyoriy | null | CSS qoidalariga qo'shimcha ravishda yaratish uchun mahalliy CSS o'zgaruvchilari xaritasi. |
state |
Ixtiyoriy | null | Yaratiladigan psevdo-sinf variantlari roʻyxati (masalan, :hover yoki :focus ). |
responsive |
Ixtiyoriy | false |
Mantiqiy javob beruvchi sinflar yaratilishi kerakligini ko'rsatadi. |
rfs |
Ixtiyoriy | false |
RFS bilan suyuqlikni qayta o'lchashni yoqish uchun mantiqiy . |
print |
Ixtiyoriy | false |
Chop etish sinflarini yaratish zarurligini ko'rsatadigan mantiqiy. |
rtl |
Ixtiyoriy | true |
Mantiqiy dastur RTLda saqlanishi kerakligini ko'rsatadi. |
API tushuntirilgan
Barcha foydali o'zgaruvchilar uslublar $utilities
jadvalimizdagi o'zgaruvchiga qo'shiladi . _utilities.scss
Utilitlarning har bir guruhi quyidagicha ko'rinadi:
$utilities: (
"opacity": (
property: opacity,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Quyidagilarni chiqaradi:
.opacity-0 { opacity: 0; }
.opacity-25 { opacity: .25; }
.opacity-50 { opacity: .5; }
.opacity-75 { opacity: .75; }
.opacity-100 { opacity: 1; }
Mulk
Kerakli property
kalit har qanday yordamchi dastur uchun o'rnatilishi kerak va u tegishli CSS xususiyatini o'z ichiga olishi kerak. Bu xususiyat yaratilgan yordam dasturining qoidalar to'plamida ishlatiladi. Kalit o'tkazib yuborilsa class
, u standart sinf nomi sifatida ham xizmat qiladi. Yordamchi dasturni ko'rib chiqing text-decoration
:
$utilities: (
"text-decoration": (
property: text-decoration,
values: none underline line-through
)
);
Chiqish:
.text-decoration-none { text-decoration: none !important; }
.text-decoration-underline { text-decoration: underline !important; }
.text-decoration-line-through { text-decoration: line-through !important; }
Qiymatlar
Yaratilgan sinf nomlari va qoidalarida values
ko'rsatilgan qiymatlar ishlatilishi kerakligini belgilash uchun kalitdan foydalaning. property
Ro'yxat yoki xarita bo'lishi mumkin (utilitalarda yoki Sass o'zgaruvchisida o'rnatilgan).
Ro'yxat sifatida, text-decoration
yordam dasturlari kabi :
values: none underline line-through
opacity
Utilitlar kabi xarita sifatida :
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
Ro'yxat yoki xaritani o'rnatuvchi Sass o'zgaruvchisi sifatida, bizning position
yordamchi dasturlarimizdagi kabi :
values: $position-values
Sinf
Kompilyatsiya qilingan CSS-da ishlatiladigan sinf prefiksini o'zgartirish uchun class
opsiyadan foydalaning. Masalan, dan ga o'zgartirish .opacity-*
uchun .o-*
:
$utilities: (
"opacity": (
property: opacity,
class: o,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Chiqish:
.o-0 { opacity: 0 !important; }
.o-25 { opacity: .25 !important; }
.o-50 { opacity: .5 !important; }
.o-75 { opacity: .75 !important; }
.o-100 { opacity: 1 !important; }
CSS o'zgaruvchan yordamchi dasturlari
css-var
Mantiqiy parametrni o'rnating true
va API odatdagi property: value
qoidalar o'rniga berilgan selektor uchun mahalliy CSS o'zgaruvchilarini yaratadi. .text-opacity-*
Kommunal xizmatlarimizni ko'rib chiqing :
$utilities: (
"text-opacity": (
css-var: true,
class: text-opacity,
values: (
25: .25,
50: .5,
75: .75,
100: 1
)
),
);
Chiqish:
.text-opacity-25 { --bs-text-opacity: .25; }
.text-opacity-50 { --bs-text-opacity: .5; }
.text-opacity-75 { --bs-text-opacity: .75; }
.text-opacity-100 { --bs-text-opacity: 1; }
Mahalliy CSS o'zgaruvchilari
local-vars
Yordamchi dasturlar sinfining qoidalar to'plamida mahalliy CSS o'zgaruvchilarini yaratadigan Sass xaritasini belgilash uchun opsiyadan foydalaning . Yaratilgan CSS qoidalarida o'sha mahalliy CSS o'zgaruvchilarni iste'mol qilish uchun qo'shimcha ish talab qilinishi mumkinligini unutmang. Masalan, bizning .bg-*
kommunal xizmatlarimizni ko'rib chiqing:
$utilities: (
"background-color": (
property: background-color,
class: bg,
local-vars: (
"bg-opacity": 1
),
values: map-merge(
$utilities-bg-colors,
(
"transparent": transparent
)
)
)
);
Chiqish:
.bg-primary {
--bs-bg-opacity: 1;
background-color: rgba(var(--bs-primary-rgb), var(--bs-bg-opacity)) !important;
}
Shtatlar
state
Pseudo-klass o'zgarishlarini yaratish uchun opsiyadan foydalaning . Pseudo-sinflarga misol :hover
va :focus
. Holatlar ro'yxati taqdim etilganda, o'sha psevdosinf uchun sinf nomlari yaratiladi. Masalan, hoverda shaffoflikni o'zgartirish uchun qo'shing state: hover
va siz .opacity-hover:hover
kompilyatsiya qilingan CSS-ni olasiz.
Bir nechta pseudo-klasslar kerakmi? Holatlarning boʻsh joydan ajratilgan roʻyxatidan foydalaning: state: hover focus
.
$utilities: (
"opacity": (
property: opacity,
class: opacity,
state: hover,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Chiqish:
.opacity-0-hover:hover { opacity: 0 !important; }
.opacity-25-hover:hover { opacity: .25 !important; }
.opacity-50-hover:hover { opacity: .5 !important; }
.opacity-75-hover:hover { opacity: .75 !important; }
.opacity-100-hover:hover { opacity: 1 !important; }
Javobgar
Barcha to'xtash nuqtalari bo'ylab responsive
sezgir yordamchi dasturlarni (masalan, ) yaratish uchun mantiqiy qiymatni qo'shing ..opacity-md-25
$utilities: (
"opacity": (
property: opacity,
responsive: true,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Chiqish:
.opacity-0 { opacity: 0 !important; }
.opacity-25 { opacity: .25 !important; }
.opacity-50 { opacity: .5 !important; }
.opacity-75 { opacity: .75 !important; }
.opacity-100 { opacity: 1 !important; }
@media (min-width: 576px) {
.opacity-sm-0 { opacity: 0 !important; }
.opacity-sm-25 { opacity: .25 !important; }
.opacity-sm-50 { opacity: .5 !important; }
.opacity-sm-75 { opacity: .75 !important; }
.opacity-sm-100 { opacity: 1 !important; }
}
@media (min-width: 768px) {
.opacity-md-0 { opacity: 0 !important; }
.opacity-md-25 { opacity: .25 !important; }
.opacity-md-50 { opacity: .5 !important; }
.opacity-md-75 { opacity: .75 !important; }
.opacity-md-100 { opacity: 1 !important; }
}
@media (min-width: 992px) {
.opacity-lg-0 { opacity: 0 !important; }
.opacity-lg-25 { opacity: .25 !important; }
.opacity-lg-50 { opacity: .5 !important; }
.opacity-lg-75 { opacity: .75 !important; }
.opacity-lg-100 { opacity: 1 !important; }
}
@media (min-width: 1200px) {
.opacity-xl-0 { opacity: 0 !important; }
.opacity-xl-25 { opacity: .25 !important; }
.opacity-xl-50 { opacity: .5 !important; }
.opacity-xl-75 { opacity: .75 !important; }
.opacity-xl-100 { opacity: 1 !important; }
}
@media (min-width: 1400px) {
.opacity-xxl-0 { opacity: 0 !important; }
.opacity-xxl-25 { opacity: .25 !important; }
.opacity-xxl-50 { opacity: .5 !important; }
.opacity-xxl-75 { opacity: .75 !important; }
.opacity-xxl-100 { opacity: 1 !important; }
}
Chop etish
print
Variantni yoqish, shuningdek , chop etish uchun faqat @media print { ... }
media so'rovida qo'llaniladigan yordam sinflarini yaratadi.
$utilities: (
"opacity": (
property: opacity,
print: true,
values: (
0: 0,
25: .25,
50: .5,
75: .75,
100: 1,
)
)
);
Chiqish:
.opacity-0 { opacity: 0 !important; }
.opacity-25 { opacity: .25 !important; }
.opacity-50 { opacity: .5 !important; }
.opacity-75 { opacity: .75 !important; }
.opacity-100 { opacity: 1 !important; }
@media print {
.opacity-print-0 { opacity: 0 !important; }
.opacity-print-25 { opacity: .25 !important; }
.opacity-print-50 { opacity: .5 !important; }
.opacity-print-75 { opacity: .75 !important; }
.opacity-print-100 { opacity: 1 !important; }
}
Muhimligi
API tomonidan yaratilgan barcha yordamchi dasturlar !important
komponentlar va modifikator sinflarini mo'ljallangan tarzda bekor qilishini ta'minlaydi. Siz ushbu sozlamani $enable-important-utilities
o'zgaruvchi bilan global miqyosda almashtirishingiz mumkin (birlamchi parametrlar true
).
API dan foydalanish
Endi siz API yordam dasturlari qanday ishlashini bilganingizdan so'ng, o'zingizning shaxsiy sinflaringizni qanday qo'shish va standart yordamchi dasturlarimizni o'zgartirishni o'rganing.
Utilitalarni bekor qilish
Xuddi shu kalit yordamida mavjud yordamchi dasturlarni bekor qiling. Misol uchun, agar siz qo'shimcha sezgir to'lib-toshgan yordamchi dasturlar sinflarini xohlasangiz, buni qilishingiz mumkin:
$utilities: (
"overflow": (
responsive: true,
property: overflow,
values: visible hidden scroll auto,
),
);
Utilitlarni qo'shing
$utilities
Standart xaritaga yangi yordam dasturlari bilan qo'shilishi mumkin map-merge
. Kerakli Sass fayllarimiz _utilities.scss
avval import qilinganligiga ishonch hosil qiling, so'ngra map-merge
qo'shimcha yordam dasturlaringizni qo'shish uchun foydalaning. Misol uchun, bu erda cursor
uchta qiymatga ega sezgir yordamchi dasturni qanday qo'shish mumkin.
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/utilities";
$utilities: map-merge(
$utilities,
(
"cursor": (
property: cursor,
class: cursor,
responsive: true,
values: auto pointer grab,
)
)
);
Utilitlarni o'zgartirish
$utilities
Standart xaritadagi mavjud yordamchi dasturlarni map-get
va map-merge
funksiyalari bilan o‘zgartiring. Quyidagi misolda biz yordamchi dasturlarga qo'shimcha qiymat qo'shmoqdamiz width
. Bosh harfdan boshlang map-merge
va keyin qaysi yordam dasturini o'zgartirmoqchi ekanligingizni belgilang. Yordamchi dastur parametrlari va qiymatlariga kirish va o'zgartirish uchun u yerdan o'rnatilgan "width"
xaritani oling.map-get
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/utilities";
$utilities: map-merge(
$utilities,
(
"width": map-merge(
map-get($utilities, "width"),
(
values: map-merge(
map-get(map-get($utilities, "width"), "values"),
(10: 10%),
),
),
),
)
);
Javob berishni yoqing
Siz hozirda sukut bo'yicha javob bermaydigan mavjud yordamchi dasturlar to'plami uchun javob beruvchi sinflarni yoqishingiz mumkin. Masalan, border
sinflarni sezgir qilish uchun:
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/utilities";
$utilities: map-merge(
$utilities, (
"border": map-merge(
map-get($utilities, "border"),
( responsive: true ),
),
)
);
Bu endi .border
va .border-0
har bir to'xtash nuqtasi uchun javob beruvchi o'zgarishlarni yaratadi. Siz yaratgan CSS quyidagicha ko'rinadi:
.border { ... }
.border-0 { ... }
@media (min-width: 576px) {
.border-sm { ... }
.border-sm-0 { ... }
}
@media (min-width: 768px) {
.border-md { ... }
.border-md-0 { ... }
}
@media (min-width: 992px) {
.border-lg { ... }
.border-lg-0 { ... }
}
@media (min-width: 1200px) {
.border-xl { ... }
.border-xl-0 { ... }
}
@media (min-width: 1400px) {
.border-xxl { ... }
.border-xxl-0 { ... }
}
Utilitlarni qayta nomlash
v4 yordam dasturlari etishmayaptimi yoki boshqa nomlash konventsiyasiga o'rganib qolganmisiz? Utilitlar API-dan ma'lum bir yordam dasturining natijasini bekor qilish uchun foydalanish mumkin class
, masalan, .ms-*
yordamchi dasturlarning nomini eskish deb o'zgartirish uchun .ml-*
:
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/utilities";
$utilities: map-merge(
$utilities, (
"margin-start": map-merge(
map-get($utilities, "margin-start"),
( class: ml ),
),
)
);
Utilitlarni olib tashlang
Guruh tugmachasini ga o'rnatish orqali har qanday standart yordamchi dasturlarni olib tashlang null
. Masalan, barcha width
yordamchi dasturlarimizni o'chirish uchun a yarating $utilities
map-merge
va ichiga qo'shing "width": null
.
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/utilities";
$utilities: map-merge(
$utilities,
(
"width": null
)
);
RTL-da yordam dasturini olib tashlang
Ba'zi chekka holatlar RTL uslubini qiyinlashtiradi , masalan, arab tilidagi qatorlar. rtl
Shunday qilib, quyidagi parametrni o'rnatish orqali yordam dasturlarini RTL chiqishidan chiqarib tashlash mumkin false
:
$utilities: (
"word-wrap": (
property: word-wrap word-break,
class: text,
values: (break: break-word),
rtl: false
),
);
Chiqish:
/* rtl:begin:remove */
.text-break {
word-wrap: break-word !important;
word-break: break-word !important;
}
/* rtl:end:remove */
Bu RTLCSS remove
boshqaruv direktivasi tufayli RTL da hech narsa chiqarmaydi .