Skip to content

Commit

Permalink
feat: allow ignoring specific component instances (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelFranken authored Apr 23, 2024
1 parent 5153cbf commit 1c461e8
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
5 changes: 5 additions & 0 deletions packages/code/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const defaultConfig: IConfiguration = {
variableNameTransformations: {
lowercase: false,
},
ignoredComponentInstances: [],
}

export class Configuration implements IConfiguration {
Expand All @@ -32,6 +33,7 @@ export class Configuration implements IConfiguration {
public theme: IConfiguration['theme']
public newBuilder: IConfiguration['newBuilder']
public variableNameTransformations: IConfiguration['variableNameTransformations']
public ignoredComponentInstances: IConfiguration['ignoredComponentInstances']

public readonly config: IConfiguration

Expand All @@ -51,13 +53,16 @@ export class Configuration implements IConfiguration {
else
this.config = defu(defaults[0], ...defaults.slice(1), defaultConfig) as IConfiguration

this.config.ignoredComponentInstances = config?.ignoredComponentInstances || defaultConfig.ignoredComponentInstances

this.mode = this.config.mode
this.unit = this.config.unit
this.variantGroup = this.config.variantGroup
this.nearestInference = this.config.nearestInference
this.theme = this.config.theme
this.newBuilder = this.config.newBuilder
this.variableNameTransformations = this.config.variableNameTransformations
this.ignoredComponentInstances = this.config.ignoredComponentInstances
}

public get colorLookup(): InferenceColorMap {
Expand Down
5 changes: 4 additions & 1 deletion packages/code/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ PluginMessages.on('variant-group-changed', async ({ variantGroup }) => {
})

PluginMessages.on('variable-name-transformations-changed', async ({ variableNameTransformations }) => {
console.log('received event', variableNameTransformations)
configurationManager.updateConfig({ variableNameTransformations }).then(generate)
})

PluginMessages.on('ignored-component-instances-changed', async ({ ignoredComponentInstances }) => {
configurationManager.updateConfig({ ignoredComponentInstances }).then(generate)
})

PluginMessages.on('new-builder-changed', async ({ newBuilder }) => {
configurationManager.updateConfig({ newBuilder }).then(generate)
})
Expand Down
5 changes: 4 additions & 1 deletion packages/code/src/parsers/figma-node.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ class FigmaNodeParser {
* @param node - The instance node to process.
* @returns {TreeNode} The generated tree node for the instance.
*/
private createInstanceNode(node: InstanceNode): TreeNode<InstanceNodeData> {
private createInstanceNode(node: InstanceNode): TreeNode<InstanceNodeData> | null {
if (this.config.ignoredComponentInstances.includes(node.name))
return null

return {
children: [],
data: {
Expand Down
7 changes: 7 additions & 0 deletions packages/types/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ interface VariableNameTransformationsChangedPluginMessageData {
variableNameTransformations: VariableNameTransformations
}

export type IgnoredComponentInstancesChangedPluginMessage = BasePluginMessage<'ignored-component-instances-changed', IgnoredComponentInstancesChangedPluginMessageData>

interface IgnoredComponentInstancesChangedPluginMessageData {
ignoredComponentInstances: string[]
}

export type NewBuilderChangedPluginMessage = BasePluginMessage<'new-builder-changed', NewBuilderChangedPluginMessageData>

interface NewBuilderChangedPluginMessageData {
Expand Down Expand Up @@ -112,6 +118,7 @@ export type PluginMessage =
| ModeChangedPluginMessage
| NearestChangedPluginMessage
| VariantGroupChangedPluginMessage
| IgnoredComponentInstancesChangedPluginMessage
| VariableNameTransformationsChangedPluginMessage
| NotificationPluginMessage
| UnitChangedPluginMessage
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export interface IConfiguration {
theme: Theme
newBuilder: boolean
variableNameTransformations: VariableNameTransformations
ignoredComponentInstances: string[]
}
23 changes: 21 additions & 2 deletions packages/ui/src/components/configuration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { computed } from 'vue'
import { storeToRefs } from 'pinia'
import Switch from './inputs/switch.vue'
import Select from './inputs/select.vue'
import type { SelectOption } from './inputs/select.vue'
import Select from './inputs/select.vue'
import { useConfiguration } from '@/stores/useConfiguration'
const { configuration } = storeToRefs(useConfiguration())
Expand All @@ -22,6 +22,13 @@ const shouldLowercaseVariableNames = computed({
},
})
const ignoredComponentInstancesModel = computed({
get: () => configuration.value.ignoredComponentInstances.join(', '),
set: (ignoredComponentInstances) => {
configuration.value.ignoredComponentInstances = ignoredComponentInstances.split(',').map(name => name.trim()).filter(name => name.length > 0)
},
})
const options: SelectOption[] = [
{
value: 'inferred',
Expand All @@ -35,7 +42,7 @@ const options: SelectOption[] = [
</script>

<template>
<div class="font-sans text-xs font-semibold color-$figma-color-text flex gap-4">
<div class="font-sans text-xs font-semibold color-$figma-color-text flex gap-4 overflow-x-scroll w-full">
<div>
<h2>
Mode
Expand Down Expand Up @@ -81,5 +88,17 @@ const options: SelectOption[] = [

<Switch v-model="configuration.newBuilder" class="mt-2" />
</div>

<div>
<h2>
Ignored Component Instances
</h2>

<input
v-model="ignoredComponentInstancesModel"
class="w-32 mt-2 p-2 border border-$figma-color-border rounded"
placeholder="Comma separated list of component instance names"
>
</div>
</div>
</template>
1 change: 1 addition & 0 deletions packages/ui/src/stores/useConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const useConfiguration = defineStore('configuration-store', () => {
watch(() => configuration.value.variantGroup, (variantGroup: boolean) => emitPluginMessage('variant-group-changed', { variantGroup }))
watch(() => configuration.value.mode, (mode: Mode) => emitPluginMessage('mode-changed', { mode }))
watch(() => configuration.value.variableNameTransformations, (variableNameTransformations: VariableNameTransformations) => emitPluginMessage('variable-name-transformations-changed', { variableNameTransformations: toRaw(variableNameTransformations) }), { deep: true })
watch(() => configuration.value.ignoredComponentInstances, (ignoredComponentInstances: string[]) => emitPluginMessage('ignored-component-instances-changed', { ignoredComponentInstances: toRaw(ignoredComponentInstances) }))
watch(() => configuration.value.newBuilder, (newBuilder: boolean) => emitPluginMessage('new-builder-changed', { newBuilder }))
})

Expand Down

0 comments on commit 1c461e8

Please sign in to comment.