-
-
Notifications
You must be signed in to change notification settings - Fork 286
Expand file tree
/
Copy pathvalidate-condition.ts
More file actions
42 lines (35 loc) · 1.31 KB
/
validate-condition.ts
File metadata and controls
42 lines (35 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import type { Conditions, ConditionObjectQuery } from '@pandacss/types'
import type { AddError } from '../types'
import { isString } from '@pandacss/shared'
const validateObjectCondition = (obj: ConditionObjectQuery, addError: AddError) => {
for (const [key, value] of Object.entries(obj)) {
if (!key.startsWith('@') && !key.includes('&')) {
addError('conditions', `Selectors should contain the \`&\` character: \`${key}\``)
}
if (value === '@slot') continue
if (typeof value === 'object' && value !== null) {
validateObjectCondition(value, addError)
}
}
}
export const validateConditions = (conditions: Conditions | undefined, addError: AddError) => {
if (!conditions) return
Object.values(conditions).forEach((condition) => {
if (isString(condition)) {
if (!condition.startsWith('@') && !condition.includes('&')) {
addError('conditions', `Selectors should contain the \`&\` character: \`${condition}\``)
}
return
}
if (Array.isArray(condition)) {
condition.forEach((c) => {
if (!c.startsWith('@') && !c.includes('&')) {
addError('conditions', `Selectors should contain the \`&\` character: \`${c}\``)
}
})
return
}
// Object syntax with @slot markers
validateObjectCondition(condition, addError)
})
}