MCPcopy Create free account
hub / github.com/fontsource/fontsource / VariableAdvanced

Function VariableAdvanced

website/app/components/preview/InstallCode.tsx:125–229  ·  view source on GitHub ↗
({ metadata, variable }: InstallCodeProps)

Source from the content-addressed store, hash-verified

123};
124
125const VariableAdvanced = ({ metadata, variable }: InstallCodeProps) => {
126 const [isActive, setActive] = useState<ActiveVariants>({
127 axes: {
128 wght: true,
129 },
130 display: 'swap',
131 subsets: [metadata.defSubset],
132 });
133
134 // Return early if no variable data
135 if (!variable) return null;
136
137 const handleActiveSubset = (value: string) => {
138 // Return early if only one subset is selected and it is the current one
139 if (isActive.subsets.length === 1 && isActive.subsets.includes(value))
140 return;
141
142 setActive((prev) => {
143 if (prev.subsets.includes(value)) {
144 return {
145 ...prev,
146 subsets: prev.subsets.filter((subset) => subset !== value),
147 };
148 }
149
150 return {
151 ...prev,
152 subsets: [...prev.subsets, value],
153 };
154 });
155 };
156
157 const handleActiveDisplay = (value: string) => {
158 setActive((prev) => ({
159 ...prev,
160 display: value,
161 }));
162 };
163
164 const handleActiveVariant = (value: string | number) => {
165 setActive((prev) => ({
166 ...prev,
167 axes: toggleVariableAxis(prev.axes, value),
168 }));
169 };
170
171 const isItal = isActive.axes.ital;
172
173 const css = buildVariablePreviewCSS(metadata, variable, {
174 activeAxes: Object.keys(isActive.axes).filter(
175 (axis) => isActive.axes[axis],
176 ),
177 subsets: isActive.subsets,
178 style: isItal ? 'italic' : 'normal',
179 display: isActive.display,
180 resolver: ({ source }) =>
181 `@fontsource-variable/${metadata.id}/files/${source.filename}`,
182 });

Callers

nothing calls this directly

Calls 1

buildVariablePreviewCSSFunction · 0.90

Tested by

no test coverage detected